#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  mp[0] = -1;
  string s;
  cin >> s;
  int sum = 0, res = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '1') {
      sum += 1;
    } else {
      sum -= 1;
    }
    if (mp.find(sum) != mp.end()) {
      res = max(res, i - mp[sum]);
    } else {
      mp[sum] = i;
    }
  }
  cout << res;
}
