#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int a[n];
  for (long long int i = 0; i <= n - 1; i++) {
    if (s[i] == '1')
      a[i] = 1;
    else
      a[i] = -1;
  }
  long long int b[n];
  long long int sum = 0;
  map<long long int, long long int> m;
  long long int k = 0;
  vector<long long int> v[n + 1];
  for (long long int i = 0; i <= n - 1; i++) {
    sum += a[i];
    if (!m[sum]) m[sum] = ++k;
    b[i] = sum;
  }
  v[m[0]].push_back(0);
  for (long long int i = 0; i <= n - 1; i++) {
    v[m[b[i]]].push_back(i + 1);
  }
  long long int len = 0;
  for (long long int i = 1; i <= n; i++) {
    if (!v[i].empty()) {
      len = max(v[i][v[i].size() - 1] - v[i][0], len);
    }
  }
  cout << len;
}
