#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<pair<char, int> > v;
  for (int i = 0; i < n; ++i) {
    int cnt = 0;
    if (s[i] == 'G') {
      while (i < n && s[i] == 'G') {
        i++;
        cnt++;
      }
      v.push_back(make_pair('G', cnt));
    } else {
      while (i < n && s[i] == 'S') {
        i++;
        cnt++;
      }
      v.push_back(make_pair('S', cnt));
    }
    i--;
  }
  if (v.size() == 1) {
    if (v[0].first == 'S') {
      cout << 0 << endl;
      return 0;
    } else {
      cout << v[0].second << endl;
      return 0;
    }
  } else {
    vector<int> g, ss;
    for (int i = 0; i < v.size(); ++i) {
      if (v[i].first == 'G')
        g.push_back(v[i].second);
      else {
        ss.push_back(v[i].second);
      }
    }
    if (g.size() == 2) {
      for (int i = 0; i < v.size(); ++i) {
        if (v[i].first == 'G') {
          if (v[i + 1].second == 1) {
            cout << g[0] + g[1] << endl;
            return 0;
          } else {
            cout << max(g[0], g[1]) + 1 << endl;
            return 0;
          }
        }
      }
    } else if (g.size() == 1) {
      cout << g[0] << endl;
      return 0;
    } else {
      int ans = INT_MIN;
      for (int i = 0; i < g.size(); ++i) {
        ans = max(ans, g[i]);
      }
      for (int i = 0; i < v.size(); ++i) {
        if (i == v.size() - 1 && v[i].first == 'G') {
          ans = max(ans, v[i].second + 1);
        }
        if (v[i].first == 'G') {
          if (v[i + 1].second == 1) {
            if (i + 2 != v.size()) {
              ans = max(ans, v[i].second + v[i + 2].second + 1);
            } else {
              ans = max(ans, v[i].second + 1);
            }
          } else {
            ans = max(ans, v[i].second + 1);
          }
        }
      }
      cout << ans << endl;
    }
  }
}
