#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  char *data;
  scanf("%d", &n);
  data = new char[n];
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }
  int numG = 0;
  vector<vector<int>> d;
  int curMax = 0;
  for (int i = 0; i < n; i++) {
    if (data[i] == 'G') {
      numG++;
      curMax++;
    } else {
      vector<int> r = {i - curMax, i - 1, curMax};
      curMax = 0;
      d.push_back(r);
    }
  }
  if (curMax != 0) {
    vector<int> r = {n - curMax, n - 1, curMax};
    curMax = 0;
    d.push_back(r);
  }
  int m = 0;
  for (int i = 0; i < d.size(); i++) {
    if (d[i][2] + 1 > m && d[i][2] != numG) {
      m = d[i][2] + 1;
    } else if (d[i][2] > m) {
      m = d[i][2];
    }
  }
  for (int i = 0; i < d.size() - 1; i++) {
    int res = d[i][2] + d[i + 1][2];
    if (res != numG && res + 1 > m) {
      m = res + 1;
    } else if (res > m) {
      m = res;
    }
  }
  printf("%d\n", m);
}
