#include <bits/stdc++.h>
using namespace std;
int a[100022], flag[6][100022], l[6][100022], r[6][100022];
int main() {
  int n, sum, temp;
  while (~scanf("%d", &n)) {
    sum = 0;
    memset(l, -1, sizeof(l));
    memset(r, -1, sizeof(r));
    memset(flag, 0, sizeof(flag));
    l[0][0] = 0;
    flag[0][0] = 1;
    for (int i = 0; i < n; i++) {
      scanf("%1d", &a[i]);
      if (a[i] == 0) a[i] = -1;
      sum += a[i];
      if (sum < 0) {
        temp = -sum;
        if (flag[1][temp] == 0) {
          flag[1][temp] = 1;
          l[1][temp] = i;
        } else
          r[1][temp] = i;
      } else {
        temp = sum;
        if (flag[0][temp] == 0) {
          flag[0][temp] = 1;
          l[0][temp] = i;
        } else
          r[0][temp] = i;
      }
    }
    int ans, maxt = 0;
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < n; j++) {
        if (l[i][j] != -1 && r[i][j] != -1) {
          ans = r[i][j] - l[i][j];
          if (j == 0) ans += 1;
          if (ans > maxt) maxt = ans;
        }
      }
    printf("%d\n", maxt);
  }
  return 0;
}
