#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const double PI = 3.1415926535897932;
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int T = 1;
  while (T--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    map<int, int> m;
    int z = 0, o = 0, ans = 0;
    m[0] = -1;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0')
        z++;
      else
        o++;
      if (m.find((o - z)) != m.end()) {
        ans = max(ans, i - m[o - z]);
      } else {
        m[(o - z)] = i;
      }
    }
    cout << ans << '\n';
  }
}
