#include <bits/stdc++.h>
using namespace std;
const int dim = 100005;
int dif[2 * dim + 5], n, minindx[2 * dim + 5];
string s;
int main() {
  int i, j, unu = 0, zero = 0, ans = -1, idx;
  cin >> n;
  cin >> s;
  memset(minindx, -1, (2 * dim + 5) * sizeof(int));
  for (i = 1; i <= n; i++) {
    unu += (s[i - 1] == '1');
    zero += (s[i - 1] == '0');
    dif[i] = zero - unu + dim;
    if (zero - unu == 0) {
      ans = max(ans, i);
    }
    if (minindx[dif[i]] == -1) {
      minindx[dif[i]] = i;
    }
  }
  for (i = 1; i <= n; i++) {
    idx = minindx[dif[i]];
    if (idx != -1) {
      ans = max(ans, i - idx);
    }
  }
  cout << ans;
  return 0;
}
