#include <bits/stdc++.h>
using namespace std;
vector<string> v;
int mx;
int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'G') {
      string ss = "";
      if (i == 1 || i == 0)
        ss += "SS";
      else
        ss += s[i - 2], ss += 'S';
      int j;
      for (j = i; j < n; ++j) {
        if (s[j] == 'S') {
          ss += 'S', ss += s[j + 1];
          break;
        } else
          ss += 'G';
        if (j == n - 1) ss += "SS";
      }
      v.push_back(ss);
      i = j;
    }
  }
  for (int i = 0; i < v.size(); ++i) {
    if (v.size() > 2) {
      if (v[i][v[i].size() - 1] == 'G') {
        mx = max(mx, int(v[i].size() - 4 + v[i + 1].size() - 3));
      } else if (v[i][0] == 'G') {
        mx = max(mx, int(v[i].size() - 4 + v[i - 1].size() - 3));
      } else {
        mx = max(mx, int(v[i].size() - 3));
      }
    } else if (v.size() == 2) {
      if (v[i][v[i].size() - 1] == 'G') {
        mx = max(mx, int(v[i].size() - 4 + v[i + 1].size() - 4));
      } else if (v[i][0] == 'G') {
        mx = max(mx, int(v[i].size() - 4 + v[i - 1].size() - 4));
      } else {
        mx = max(mx, int(v[i].size() - 3));
      }
    } else {
      mx = max(mx, int(v[i].size() - 4));
    }
  }
  cout << mx;
}
