#include <bits/stdc++.h>
const int N = (int)2e5 + 7;
const int MAXN = (int)1e3 + 7;
const int LN = 20;
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-6;
const int MOD = 998244353;
const long long LINF = (int64_t)1e15;
const int INF = (int)1e9;
const int DEL = (int)1e9 + 7;
using namespace std;
int main() {
  int n, min_pos[N] = {};
  fill(min_pos, min_pos + N, INF);
  cin >> n;
  string s;
  cin >> s;
  int b = 0;
  min_pos[N / 2] = -1;
  for (int i = 0; i < n; i++) {
    b = b + (s[i] == '0' ? -1 : 1);
    min_pos[b + N / 2] = min(i, min_pos[b + N / 2]);
  }
  int ans = 0;
  b = 0;
  for (int i = 0; i < n; i++) {
    b = b + (s[i] == '0' ? -1 : 1);
    ans = max(ans, i - min_pos[b + N / 2]);
  }
  cout << ans;
}
