#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1E9 + 7;
long long findSubArray(long long arr[], long long n) {
  long long maxsize = -1, startindex;
  long long sumleft[n];
  long long i, min, max;
  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)
    return 0;
  else
    return maxsize;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("inp.txt", "r")) {
    freopen("inp.txt", "r", stdin);
    freopen("outp.txt", "w", stdout);
  }
  long long n, i;
  cin >> n;
  string s;
  cin >> s;
  long long a[n];
  for (i = 0; i < n; i++) {
    if (s[i] == '0')
      a[i] = 0;
    else
      a[i] = 1;
  }
  cout << findSubArray(a, n);
  return 0;
}
