#include <bits/stdc++.h>
using namespace std;
int main() {
  map<long long, long long> M;
  string vards;
  long long sk, rez = 0, b = 0;
  cin >> sk >> vards;
  M[0] = -1;
  for (long long i = 0; i < sk; i++) {
    if (vards[i] == '0')
      b--;
    else
      b++;
    if (M.count(b)) {
      rez = max(rez, i - M[b]);
    } else {
      M[b] = i;
    }
  }
  cout << rez;
  return 0;
}
