#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, l, n, x = 0, z = 0, q = 1, w = 1, e = 1;
  string s;
  cin >> n;
  cin >> s;
  int a[n], b[n], c[n];
  unordered_map<int, int> mp;
  unordered_map<int, int> cnt;
  if (s[0] == '0') {
    a[0] = 1;
    b[0] = 0;
  } else {
    b[0] = 1;
    a[0] = 0;
  }
  vector<int> v;
  for (i = 1; i < n; i++) {
    if (s[i] == '0') {
      a[i] = a[i - 1] + 1;
      b[i] = b[i - 1];
    } else {
      b[i] = b[i - 1] + 1;
      a[i] = a[i - 1];
    }
  }
  for (i = 0; i < n; i++) {
    c[i] = a[i] - b[i];
    if (cnt[c[i]] == 0) {
      mp[c[i]] = i;
    } else {
      z = 1;
    }
    cnt[c[i]]++;
  }
  unordered_set<int> sw;
  for (i = 0; i < n; i++) {
    if (sw.count(c[i])) {
      j = i - mp[c[i]];
      x = max(x, j);
    } else {
      sw.insert(c[i]);
    }
    if (c[i] == 0) {
      j = i + 1;
      x = max(x, j);
    }
  }
  cout << x << "\n";
}
