#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 = 0 ; 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 > 0) distance.insert(dist); else flag = false; } if(!flag) cout<<-1<<endl; else cout<<distance.size()<<endl; return 0; }