#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<pair<int, int>> v;
  int l = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[l]) {
      if (s[l] == 'G') v.push_back({l, i - 1});
      l = i;
    }
  }
  if (s[l] == 'G') v.push_back({l, n - 1});
  int ans = 0;
  if (v.size() > 1) {
    for (int i = 0; i < v.size(); i++) {
      ans = max(ans, v[i].second - v[i].first + 2);
    }
  }
  if (v.size() > 1) {
    for (int i = 0; i < v.size() - 1; i++) {
      if (v[i].second + 2 == v[i + 1].first) {
        int cur = 0;
        if (v.size() > 2) cur++;
        ans = max(v[i].second - v[i].first + 1 + v[i + 1].second -
                      v[i + 1].first + 1 + cur,
                  ans);
      }
    }
  }
  if (v.size() == 1) ans = max(ans, v[0].second - v[0].first + 1);
  cout << ans;
  return 0;
}
