#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
int main() {
  long long i, j, n, m, t;
  string s;
  cin >> n;
  cin >> s;
  long long ans = 0;
  long long cnt = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == '1')
      cnt++;
    else
      cnt--;
    if (cnt == 0) {
      ans = max(ans, i + 1);
    } else if (mp[cnt] == 0)
      mp[cnt] = i + 1;
    else {
      ans = max(ans, i + 1 - mp[cnt]);
    }
  }
  cout << ans << endl;
}
