#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
long long a[202020], b[202020];
vector<long long> v;
pair<long long, long long> p;
map<string, int> mp;
set<long long> st;
set<long long>::iterator it;
string s;
long long q, t, n, m, k, z, x, y, d, sum, cnt, mx = 0;
int main() {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> s;
  s = "S" + s + "SS";
  n += 3;
  for (int i = 0; i < n; i++)
    if (s[i] == 'G')
      cnt++;
    else
      v.push_back(i);
  int i1 = 0, i2 = 1, i3 = 2;
  while (i3 < v.size()) {
    if (v[i2] - v[i1] > 1 && v[i3] - v[i2] > 1) {
      sum = (v[i3] - v[i2] - 1) + (v[i2] - v[i1] - 1);
      if (sum < cnt) sum++;
      mx = max(mx, sum);
    } else if (v[i2] - v[i1] > 1) {
      sum = v[i2] - v[i1] - 1;
      if (sum < cnt) sum++;
      mx = max(mx, sum);
    } else if (v[i3] - v[i2] > 1) {
      sum = v[i3] - v[i2] - 1;
      if (sum < cnt) sum++;
      mx = max(mx, sum);
    }
    i1++, i2++, i3++;
  }
  cout << mx;
}
