#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set> using namespace std; int main(){
int n,m;
cin >> n >> m;
set<int> distance;
bool flag = true;
for(int i = ; i < n; ++ i){
string rectangle;
cin >> rectangle;
int dwarf_pos = rectangle.find('G');
int candy_pos = rectangle.find('S');
int dist = candy_pos - dwarf_pos;
if(dist > ) distance.insert(dist);
else flag = false;
}
if(!flag) cout<<-<<endl;
else cout<<distance.size()<<endl;
return ;
}