#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1010;   set<int> ans;   int n, m;   char a[MAXN][MAXN];   int posk[MAXN];   int posG[MAXN];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  S ) {           posk[i] = j;         }         if (a[i][j] ==  G ) {           posG[i] = j;         }       }     }     for (int i = 0; i < n; i++) {       if (posG[i] > posk[i]) {         cout << -1;         return 0;       } else {         ans.insert((int)posG[i] - posk[i] + 1);       }     }     cout << ans.size();     return 0;   }   