#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000005];
int s;
map<int, int> g;
int ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    char c;
    cin >> c;
    a[i] = (c == '0' ? 1 : -1);
    s += a[i];
  }
  int u = s;
  for (int i = 0; i < n; ++i) {
    g[u] = i;
    u -= a[i];
  }
  g[u] = n;
  int v = 0;
  for (int i = 0; i < n; ++i) {
    if (g.find(s - v) != g.end()) {
      int j = g[s - v];
      ans = max(ans, j - i);
    }
    v += a[i];
  }
  cout << ans << endl;
  return 0;
}
