#include <bits/stdc++.h>
const double PI = acos(-1.0);
using namespace std;
void fast_in_out() {
  std::ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
}
void pause() {}
int dx[] = {0, 0, -1, -1, -1, 1, 1, 1};
int dy[] = {-1, 1, 0, 1, -1, -1, 0, 1};
int main() {
  fast_in_out();
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  vector<pair<int, int>> v;
  int last = 0;
  bool f = 0;
  for (int i = 0; i <= s.size(); i++) {
    if (i == s.size() && f) {
      v.push_back({last, s.size() - 1});
      ans = max(ans, (int)n - last);
      break;
    }
    if (s[i] == 'G' && f) continue;
    if (s[i] == 'G' && !f) {
      f = 1;
      last = i;
    }
    if (s[i] != 'G' && f) {
      f = 0;
      v.push_back({last, i - 1});
      ans = max(ans, i - last);
    }
  }
  if (v.size() > 1) ans++;
  for (int i = 0; (i + 1) < v.size(); i++) {
    if (v[i].second + 2 == v[i + 1].first) {
      if (v.size() > 2)
        ans = max(ans, v[i].second - v[i].first + v[i + 1].second -
                           v[i + 1].first + 3);
      else
        ans = max(ans, v[i].second - v[i].first + v[i + 1].second -
                           v[i + 1].first + 2);
    }
  }
  cout << ans << '\n';
  pause();
  return 0;
}
