#include <bits/stdc++.h>
using namespace std;
map<int, int> last;
map<int, int> first;
map<int, int>::iterator it;
char a[100005];
int main() {
  int n;
  cin >> n;
  int b[n];
  int c[n];
  getchar();
  gets(a);
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == '0') {
      b[i] = -1;
      --count;
    } else {
      b[i] = 1;
      ++count;
    }
    c[i] = count;
  }
  for (int i = 0; i < n; i++) {
    if (first.count(c[i])) {
    } else {
      first[c[i]] = i;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (last.count(c[i])) {
    } else {
      last[c[i]] = i;
    }
  }
  if (!last.count(0)) {
    last[0] = -1;
  }
  int res = 0;
  it = first.begin();
  while (it != first.end()) {
    int num = it->first;
    int temp1 = first[num];
    int temp2 = last[num];
    if ((temp2 - temp1) > res) {
      res = temp2 - temp1;
    }
    ++it;
  }
  if (res < (last[0] + 1)) {
    res = last[0] + 1;
  }
  cout << res << endl;
  return 0;
}
