#include <bits/stdc++.h>
using namespace std;
long long MAXN = 9223372036854775807, mod = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T = 1;
  for (long long t = 0; t < T; t++) {
    long long n;
    string s;
    cin >> n >> s;
    long long x = n + 2;
    long long dp[x];
    map<long long, vector<long long>> pos;
    long long c = 0, ans = 0;
    pos[0].push_back(0);
    for (long long i = 0; i < n; i++) {
      if (s[i] == '1')
        c++;
      else
        c--;
      pos[c].push_back(i + 1);
    }
    for (auto a : pos) {
      vector<long long> x = a.second;
      long long d = x.size();
      ans = max(ans, x[d - 1] - x[0]);
    }
    cout << ans << endl;
  }
  return 0;
}
