#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  register T c = getchar();
  x = 0;
  int t = 0;
  if (c == '-') t = 1, c = getchar();
  for (; (c < 48 || c > 57); c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (t) x = -x;
}
int main() {
  long long n;
  string s;
  cin >> n >> s;
  long long zero = 0, one = 0, ans = 0;
  map<long long, long long> m;
  m[0] = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1')
      one++;
    else
      zero++;
    if (m.count(zero - one)) {
      ans = max(ans, i - m[zero - one]);
    } else
      m[zero - one] = i;
  }
  cout << ans;
}
