#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const long long int mxn = 1e5 + 1;
const string fuck = "fuck";
void solve() {
  long long int n;
  string s;
  cin >> n >> s;
  s = ' ' + s;
  map<long long int, long long int> dif;
  long long int cnt1 = 0, cnt0 = 0;
  long long int ans = -1;
  dif[0] = 0;
  for (long long int i = 1; i <= n; i++) {
    if (s[i] == '1')
      cnt1++;
    else
      cnt0++;
    if (dif[cnt1 - cnt0] == 0 && cnt1 - cnt0 != 0) {
      dif[cnt1 - cnt0] = i;
    }
    ans = max(ans, i - dif[cnt1 - cnt0]);
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int cse = 1;
  while (cse--) {
    solve();
    cout << endl;
  }
}
