#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> number;
  cin >> n;
  number.resize(n + 1);
  for (int i = 1; i <= n; ++i) {
    char temp;
    cin >> temp;
    number[i] = temp - '0';
  }
  int status_cur = 0;
  vector<pair<int, int>> status;
  status.resize(n * 2 + 1);
  for (int i = 1; i <= n; ++i) {
    if (number[i])
      status_cur++;
    else
      status_cur--;
    int temp = status_cur;
    if (status_cur < 0) status_cur = n + abs(status_cur);
    if (!status_cur)
      status[status_cur].second = i;
    else {
      if (status[status_cur].first == 0) {
        status[status_cur].first = i;
        status[status_cur].second = i;
      } else
        status[status_cur].second = i;
    }
    status_cur = temp;
  }
  int m = 0;
  for (auto i : status) {
    m = max(m, i.second - i.first);
  }
  cout << m;
  return 0;
}
