import std.stdio, std.conv, std.array, std.string, std.algorithm, std.range;

// from https://ei1333.github.io/luzhiled/snippets/structure/union-find.html
class UnionFind {
  public:
    long[] par;

    this(long size) {
      par = new long[](size);
      foreach (i; 0..size) {
        par[i] = -1;
      }
    }

    long size(long x) {
      return -(par[find(x)]);
    }

    long find(long x) {
      if (par[x] < 0) {
        return x;
      }
      par[x] = find(par[x]);
      return par[x];
    }

    bool same(long x, long y) {
      return !unite(x, y);
    }

    bool unite(long x, long y) {
      x = find(x);
      y = find(y);

      if (x == y) {
        return false;
      }
      if (par[x] > par[y]) {
        par[y] += par[x];
        par[x] = y;
      } else {
        par[x] += par[y];
        par[y] = x;
      }
      return true;
    }
}


void main() {
  long n, m;
  readf("%d %d\n", &n, &m);

  auto uf = new UnionFind(n);
  
  long a, b;
  long[] as = new long[](m), bs = new long[](m);
  foreach (i; 0..m) {
    readf("%d %d\n", &a, &b);
    as[i] = a-1;
    bs[i] = b-1;
  }

  long[] cnt = new long[](m);
  foreach_reverse(i; 0..m) {
    a = uf.size(as[i]);
    b = uf.size(bs[i]);
    if (uf.unite(as[i], bs[i])) {
      cnt[i] = a * b;
    } else {
      cnt[i] = 0;
    }
  }

  long ans = 0;
  foreach (i; 0..m) {
    ans += cnt[i];
    writeln(ans);
  }
}
