#include <bits/stdc++.h>
using namespace std;
char ch[100010];
int main() {
  int x;
  cin >> x;
  map<int, int> val;
  val[0] = 0;
  for (int i = 1; i <= x; i++) {
    cin >> ch[i];
  }
  int ans = 0, finalAns = 0;
  for (int i = 1; i <= x; i++) {
    if (ch[i] == '0') {
      ans--;
    } else if (ch[i] == '1') {
      ans++;
    }
    int tmp;
    if (val[ans] == 0 && ans != 0)
      val[ans] = i;
    else {
      int tmp;
      if (ans == 0)
        tmp = i;
      else
        tmp = i - val[ans];
      finalAns = max(finalAns, tmp);
    }
  }
  cout << finalAns << "\n";
}
