#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string arr;
  cin >> arr;
  if (arr.find('G') == string::npos) {
    cout << 0 << endl;
    return 0;
  }
  int rightMost = arr.rfind('G');
  int length = arr.size();
  int count = 0, result = 0, swapped = -1;
  int start = -1;
  for (int i = 0; i < length; i++) {
    if (arr[i] == 'G') {
      count++;
    } else if (arr[i] == 'S' && swapped == -1 && rightMost > i) {
      count++;
      swapped = i;
      swap(arr[i], arr[rightMost]);
    } else if (arr[i] == 'S' && swapped == -1 && rightMost < i) {
      count = 0;
    } else {
      swap(arr[swapped], arr[rightMost]);
      count = 0;
      i = swapped;
      swapped = -1;
    }
    result = max(result, count);
  }
  if (swapped != -1) {
    swap(arr[swapped], arr[rightMost]);
    swapped = -1;
  }
  int leftMost = arr.find('G');
  count = 0;
  for (int i = length - 1; i >= 0; i--) {
    if (arr[i] == 'G') {
      count++;
    } else if (arr[i] == 'S' && swapped == -1 && leftMost < i) {
      count++;
      swapped = i;
      swap(arr[i], arr[leftMost]);
    } else if (arr[i] == 'S' && swapped == -1 && leftMost > i) {
      count = 0;
    } else {
      swap(arr[i], arr[leftMost]);
      count = 0;
      i = swapped;
      swapped = -1;
    }
    result = max(result, count);
  }
  cout << result << endl;
}
