#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  string x;
  cin >> x;
  vector<int> v;
  int sum = 0, vs = 0;
  for (long long i = (0); i < (a); i++) {
    if (x[i] != 'S') {
      sum++;
    } else {
      v.push_back(sum);
      if (sum != 0) {
        vs++;
      }
      sum = 0;
    }
  }
  if (x[x.size() - 1] == 'G') {
    v.push_back(sum);
    vs++;
  }
  int maxi = v[0];
  for (long long i = (1); i < (v.size()); i++) {
    if (v[i] != 0 && v[i - 1] != 0 && vs >= 3) {
      maxi = max(maxi, (v[i] + v[i - 1] + 1));
    } else {
      maxi = max(maxi, (v[i] + v[i - 1]));
    }
  }
  for (long long i = (0); i < (v.size()); i++) {
    if (v[i] == maxi && vs > 1) {
      maxi++;
      break;
    }
  }
  cout << maxi;
}
