#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long x, unsigned long long y) {
  return y == 0 ? x : gcd(y, x % y);
}
int main() {
  unsigned long long x, y;
  unsigned long long n;
  cin >> n >> x;
  vector<string> input(n);
  for (int i = 0; i < int(n); ++i) {
    cin >> input[i];
  }
  vector<unsigned long long> d(n);
  for (int i = 0; i < int(n); ++i) {
    unsigned long long G = 0;
    unsigned long long S = 0;
    for (int j = 0; j < int(input[i].size()); ++j) {
      if (input[i][j] == 'G') {
        G = j;
      }
      if (input[i][j] == 'S') {
        S = j;
      }
    }
    if (G >= S) {
      cout << -1 << endl;
      return 0;
    } else {
      d[i] = G - S - 1;
    }
  }
  sort(d.begin(), d.end());
  unsigned long long ans = 0;
  for (int i = 0; i < int(n - 1); ++i) {
    if (d[i] != d[i + 1]) {
      ans++;
    }
  }
  cout << ans + 1 << endl;
  return 0;
}
