#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long int mod = 1e9 + 7;
const long long int mod1 = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<long long int> len;
void solve() {
  long long int n;
  string s;
  cin >> n >> s;
  s = "S" + s;
  s += "S";
  long long int ss = 0;
  long long int ans = 0;
  n += 2;
  for (long long int i = 0; i <= n - 1; i++) {
    if (s[i] == 'G') {
      long long int j = i;
      while (s[j] == 'G') j++;
      len.push_back(j - i);
      ss++;
      ans = max(ans, j - i);
      i = j;
    }
  }
  if (ss > 1) ans++;
  long long int cc = -1;
  for (long long int i = 0; i <= n - 2; i++) {
    if (s[i] == 'G' && s[i - 1] == 'S') cc++;
    if (s[i] == 'S' && s[i + 1] == 'G' && s[i - 1] == 'G') {
      ans = max(ans, len[cc] + len[cc + 1] + (ss > 2));
    }
  }
  cout << ans;
}
signed main() {
  ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  clock_t clk = clock();
  long long int t;
  t = 1;
  for (long long int i = 1; i <= t; i++) {
    solve();
  }
  cerr << '\n'
       << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
  return 0;
}
