#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, ans = 0;
string str;
map<int, int> mp;
vector<int> arr(maxn, -1);
void solve() {
  cin >> n;
  cin >> str;
  for (int i = 0; i < n; i++) {
    if (str[i] == '1') arr[i] = 1;
  }
  mp[arr[0]] = 0;
  for (int i = 1; i < n; i++) {
    arr[i] += arr[i - 1];
    if (mp.find(arr[i]) == mp.end()) mp[arr[i]] = i;
  }
  for (int i = n - 1; i >= 0; i--) {
    ans = max(ans, i - mp[arr[i]]);
    if (arr[i] == 0) ans = max(ans, i + 1);
  }
  cout << ans << "\n";
}
int main() {
  solve();
  return 0;
}
