#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  string str;
  cin >> n >> str;
  int silvers = 0;
  for (int i = 0; i < n; ++i)
    if (str[i] == 'S') silvers++;
  if (silvers == 0)
    cout << n << endl;
  else if (silvers == n)
    cout << 0 << endl;
  else {
    vector<int> v;
    int curr = 0;
    string chars = "SG";
    int golds = 0;
    for (int i = 0; i < n;) {
      int cnt = 0;
      while (i < n and str[i] == chars[curr]) {
        ++i;
        cnt++;
      }
      if (cnt > 0 and chars[curr] == 'G') golds++;
      curr ^= 1;
      v.push_back(cnt);
    }
    int off = 0;
    if (v.size() >= 4) off = 1;
    int ans = v[1] + off;
    for (int i = 3; i < v.size(); i += 2) {
      ans = max(ans, v[i] + off);
      if (v[i - 1] == 1) {
        if (golds > 2)
          ans = max(ans, v[i] + 1 + v[i - 2]);
        else
          ans = max(ans, v[i] + v[i - 2]);
      }
    }
    cout << ans << endl;
  }
}
