#include <bits/stdc++.h>
using namespace std;
long long inf = 1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long T, N, M, i, j, k, L, l, m, n;
  string str;
  cin >> N;
  cin >> str;
  vector<pair<long long, long long> > v;
  i = 0;
  j = 0;
  while (i < N) {
    j = i;
    while (i < N and str[i] == 'G') i++;
    if (i == j) i++;
    if (str[j] == 'G') {
      v.push_back(make_pair(j, i - 1));
    }
  }
  long long _max = 0;
  for (i = 0; i < v.size(); i++) {
    _max = (((_max) > (v[i].second - v[i].first + 1))
                ? (_max)
                : (v[i].second - v[i].first + 1));
  }
  M = v.size();
  for (i = 0; i < M; i++) {
    if (i < M - 1 and v.size() > 2 and v[i].second + 2 == v[i + 1].first) {
      _max = (((_max) > (v[i + 1].second - v[i].first + 1))
                  ? (_max)
                  : (v[i + 1].second - v[i].first + 1));
    } else if (i < M - 1 and v.size() == 2 and
               v[i].second + 2 == v[i + 1].first) {
      _max = (((_max) > (v[i + 1].second - v[i].first))
                  ? (_max)
                  : (v[i + 1].second - v[i].first));
    } else if (v.size() == 2) {
      _max = (((_max) > (v[i].second - v[i].first + 2))
                  ? (_max)
                  : (v[i].second - v[i].first + 2));
    } else if (v.size() > 2) {
      _max = (((_max) > (v[i].second - v[i].first + 2))
                  ? (_max)
                  : (v[i].second - v[i].first + 2));
    }
  }
  cout << _max << endl;
}
