#include <bits/stdc++.h>
const int Inf = 2e9;
long long LINF = (long long)4e18;
using namespace std;
long long mod = 1e9 + 7;
long long a[100005];
long long sum[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    a[i] = c == 'G';
  }
  long long cur = 0;
  long long cnt = 0;
  vector<pair<long long, long long>> seg;
  int pos = 0;
  long long mx = 0;
  for (int i = 1; i <= n + 1; i++) {
    if (a[i] == 1) {
      cur++;
      if (cur == 1) pos = i;
      sum[i] = cur;
    } else {
      if (cur) {
        mx = max(mx, cur);
        seg.push_back({cur, pos});
      }
      cur = 0;
    }
  }
  for (int i = 0; i < seg.size(); i++) {
    if (seg.size() > 1) {
      mx = max(mx, seg[i].first + 1);
    }
    if (i + 1 >= seg.size()) break;
    int dist = seg[i + 1].second - seg[i].second - seg[i].first;
    if (dist == 1) {
      if (seg.size() > 2)
        mx = max(mx, seg[i + 1].first + seg[i].first + 1);
      else
        mx = max(mx, seg[i + 1].first + seg[i].first);
    }
  }
  cout << mx;
  return 0;
}
