#include <bits/stdc++.h>
using namespace std;
long long const inf = 1e9;
long long mod = 1e9 + 7;
double const pi = 3.141592;
int main() {
  int n;
  cin >> n;
  string S;
  cin >> S;
  int g = 0;
  int s = 0;
  vector<pair<int, int> > v;
  if (S[0] == 'G')
    g++;
  else
    s++;
  for (int i = (1); i < (n); i++) {
    if (S[i] == 'G') {
      if (s > 0) v.push_back({s, 0});
      g++;
      s = 0;
    } else {
      if (g > 0) v.push_back({g, 1});
      s++;
      g = 0;
    }
  }
  if (g > 0) v.push_back({g, 1});
  if (s > 0) v.push_back({s, 0});
  bool lef[(int)v.size()];
  memset(lef, false, sizeof(lef));
  for (int i = (0); i < (v.size()); i++) {
    if (i > 0 && lef[i - 1])
      lef[i] = true;
    else if (i < v.size() - 1 && v[i].second == 1)
      lef[i + 1] = true;
  }
  bool rig[(int)v.size()];
  memset(rig, false, sizeof(rig));
  for (int i = (int)v.size() - 1; i >= 0; i--) {
    if (i < v.size() - 1 && rig[i + 1])
      rig[i] = true;
    else if (i - 1 >= 0 && v[i].second == 1)
      rig[i - 1] = true;
  }
  int ans = 0;
  for (auto u : v) {
    if (u.second == 1 && u.first > ans) ans = u.first;
  }
  for (int i = (1); i < (v.size() - 1); i++) {
    if (v[i].first != 1) continue;
    if (v[i - 1].second == 1 && v[i + 1].second == 1 &&
        (lef[i - 1] || rig[i + 1])) {
      ans = max(ans, v[i - 1].first + v[i + 1].first + 1);
    } else if (v[i - 1].second == 1 && v[i + 1].second == 1) {
      ans = max(ans, v[i - 1].first + v[i + 1].first);
    }
  }
  for (int i = (0); i < (v.size()); i++) {
    if (v[i].second == 1 && rig[i]) {
      ans = max(ans, v[i].first + 1);
    }
    if (v[i].second == 1 && lef[i]) {
      ans = max(ans, v[i].first + 1);
    }
  }
  cout << ans << endl;
}
