#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int maxn = 3e5 + 7;
int n, f[maxn][20], dep[maxn];
set<int> s1, s2;
int mx = 0;
long long ans = 0;
int path(int o, int p) {
  if (dep[o] < dep[p]) swap(o, p);
  int dis = dep[o] - dep[p];
  for (int i = 19; i >= 0; --i) {
    if (dep[f[o][i]] >= dep[p]) {
      o = f[o][i];
    }
  }
  if (o == p) return dis;
  for (int i = 19; i >= 0; --i) {
    if (f[o][i] != f[p][i]) {
      dis += 2 * (dep[o] - dep[f[o][i]]);
      o = f[o][i];
      p = f[p][i];
    }
  }
  return dis + 2;
}
void solve(int v) {
  int u;
  scanf("%d", &u);
  f[v][0] = u;
  dep[v] = dep[u] + 1;
  for (int i = 1; i < 20; ++i) {
    f[v][i] = f[f[v][i - 1]][i - 1];
  }
  int dis1 = s1.empty() ? 0 : path(v, *s1.begin());
  int dis2 = s2.empty() ? 0 : path(v, *s2.begin());
  if (max(dis1, dis2) < mx) return;
  if (max(dis1, dis2) > mx) {
    mx = max(dis1, dis2);
    if (dis1 >= dis2) {
      for (auto &i : s2) {
        if (path(i, v) == mx) {
          s1.insert(i);
        }
      }
      s2.clear();
      s2.insert(v);
    } else {
      for (auto &i : s1) {
        if (path(i, v) == mx) {
          s2.insert(i);
        }
      }
      s1.clear();
      s1.insert(v);
    }
  } else {
    if (dis1 >= dis2) {
      s2.insert(v);
    } else {
      s1.insert(v);
    }
  }
  ans = s1.size() + s2.size();
}
int main() {
  scanf("%d%*d", &n);
  for (int i = 0; i < 20; ++i) {
    f[1][i] = 1;
    f[2][i] = 1;
  }
  s1.insert(1);
  s2.insert(2);
  dep[2] = dep[1] + 1;
  ans = 2;
  mx = 1;
  printf("2\n");
  for (int i = 2; i <= n; ++i) {
    solve(i + 1);
    printf("%lld\n", ans);
  }
  return 0;
}
