#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const long long N = 1e6 + 5, OO = 1e16 * 1ll, mod = 1e9 + 7;
using namespace std;
int main() {
  long long n;
  string s;
  cin >> n >> s;
  long long val = 0, ans = 0;
  map<long long, long long> mp;
  for (int i = 0; i < n; i++) {
    val += (s[i] == '1') ? 1 : -1;
    if (mp[val] || !val) {
      ans = max(ans, i + 1 - mp[val]);
    } else if (!mp[val])
      mp[val] = i + 1;
  }
  cout << ans << '\n';
  return 0;
}
