#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
void amax(X& x, const Y& y) {
  if (x < y) x = y;
}
template <class X, class Y>
void amin(X& x, const Y& y) {
  if (x > y) x = y;
}
const int INF = 1e9 + 10;
const long long INFL = 1e18 + 10;
int n;
string s;
map<int, int> pos;
void process() {
  cin >> n >> s;
  pos[0] = 0;
  int sum = 0;
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == '0')
      sum--;
    else
      sum++;
    if (pos.find(sum) != pos.end())
      amax(res, i - pos[sum]);
    else
      pos[sum] = i;
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  process();
}
