#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
int arr[2000005] = {0};
int foo(int n) {
  int maxsize = -1, startindex;
  int sumleft[n];
  int min, max;
  int i;
  sumleft[0] = ((arr[0] == 0) ? -1 : 1);
  min = arr[0];
  max = arr[0];
  for (i = 1; i < n; i++) {
    sumleft[i] = sumleft[i - 1] + ((arr[i] == 0) ? -1 : 1);
    if (sumleft[i] < min) min = sumleft[i];
    if (sumleft[i] > max) max = sumleft[i];
  }
  int hash[max - min + 1];
  for (i = 0; i < max - min + 1; i++) hash[i] = -1;
  for (i = 0; i < n; i++) {
    if (sumleft[i] == 0) {
      maxsize = i + 1;
      startindex = 0;
    }
    if (hash[sumleft[i] - min] == -1)
      hash[sumleft[i] - min] = i;
    else {
      if ((i - hash[sumleft[i] - min]) > maxsize) {
        maxsize = i - hash[sumleft[i] - min];
        startindex = hash[sumleft[i] - min] + 1;
      }
    }
  }
  if (maxsize == -1) maxsize = 0;
  return maxsize;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') arr[i] = 1;
  }
  cout << foo(n);
  return 0;
}
