#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int n, aux[2 * N + 1], *p, lmax, val, sc;
int main() {
  cin >> n;
  p = aux + N;
  string s;
  for (int i = -N; i <= N; i++) {
    p[i] = -1;
  }
  p[0] = 0;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      val = -1;
    } else {
      val = 1;
    }
    sc += val;
    if (p[sc] == -1) {
      p[sc] = i + 1;
    } else {
      lmax = max(lmax, i - p[sc] + 1);
    }
  }
  cout << lmax;
  return 0;
}
