import sys
sys.setrecursionlimit(1000000)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        # 親の番号 根なら要素数(負の数)

    def find(self, x):
        """木の根を求める"""
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        """xとyの属する集合を併合"""
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        """xとyが同じ集合に属するか否か"""
        return self.find(x) == self.find(y)

    def size(self, x):
        """グループのサイズを返す"""
        return -self.parents[self.find(x)]

N , M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
uf = UnionFind(N)
AB.reverse()
ans = [N * (N - 1) // 2]
for A, B in AB:
    if uf.same(A - 1, B - 1):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uf.size(A - 1) * uf.size(B - 1))
    uf.unite(A - 1, B - 1)

for a in ans[:-1][::-1]:
    print(a) import sys sys sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        # 親の番号 根なら要素数(負の数)

    def find(self, x):
        """木の根を求める"""
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        """xとyの属する集合を併合"""
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        """xとyが同じ集合に属するか否か"""
        return self.find(x) == self.find(y)

    def size(self, x):
        """グループのサイズを返す"""
        return -self.parents[self.find(x)] UnionFind def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        # 親の番号 根なら要素数(負の数)

     __init__ self.n = n self.n self n n self.parents = [-1] * n self.parents self parents [-1] * n [-1] -1 n self self n n def find(self, x):
        """木の根を求める"""
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

     find """木の根を求める""" if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

     self.parents[x] < 0 self.parents[x] self.parents self parents x 0 return x x self.parents[x] = self.find(self.parents[x]) self.parents[x] self.parents self parents x self.find(self.parents[x]) self.find self find self.parents[x] self.parents self parents x return self.parents[x] self.parents[x] self.parents self parents x self self x x def unite(self, x, y):
        """xとyの属する集合を併合"""
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

     unite """xとyの属する集合を併合""" x = self.find(x) x self.find(x) self.find self find x y = self.find(y) y self.find(y) self.find self find y if x == y:
            return
         x == y x y return if self.parents[x] > self.parents[y]:
            x, y = y, x
         self.parents[x] > self.parents[y] self.parents[x] self.parents self parents x self.parents[y] self.parents self parents y x, y = y, x x y y x self.parents[x] += self.parents[y] self.parents[x] self.parents self parents x self.parents[y] self.parents self parents y self.parents[y] = x self.parents[y] self.parents self parents y x self self x x y y def same(self, x, y):
        """xとyが同じ集合に属するか否か"""
        return self.find(x) == self.find(y)

     same """xとyが同じ集合に属するか否か""" return self.find(x) == self.find(y) self.find(x) == self.find(y) self.find(x) self.find self find x self.find(y) self.find self find y self self x x y y def size(self, x):
        """グループのサイズを返す"""
        return -self.parents[self.find(x)] size """グループのサイズを返す""" return -self.parents[self.find(x)] -self.parents[self.find(x)] self.parents[self.find(x)] self.parents self parents self.find(x) self.find self find x self self x x N , M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M list(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split AB = [list(map(int, input().split())) for _ in range(M)] AB [list(map(int, input().split())) for _ in range(M)] uf = UnionFind(N) uf UnionFind(N) UnionFind N AB.reverse() AB.reverse AB reverse ans = [N * (N - 1) // 2] ans [N * (N - 1) // 2] N * (N - 1) // 2 N * (N - 1) N N - 1 N 1 2 for A, B in AB:
    if uf.same(A - 1, B - 1):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uf.size(A - 1) * uf.size(B - 1))
    uf.unite(A - 1, B - 1) A B AB if uf.same(A - 1, B - 1):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uf.size(A - 1) * uf.size(B - 1))
     uf.same(A - 1, B - 1) uf.same uf same A - 1 A 1 B - 1 B 1 ans.append(ans[-1]) ans.append ans append ans[-1] ans -1 ans.append(ans[-1] - uf.size(A - 1) * uf.size(B - 1)) ans.append ans append ans[-1] - uf.size(A - 1) * uf.size(B - 1) ans[-1] ans -1 uf.size(A - 1) * uf.size(B - 1) uf.size(A - 1) uf.size uf size A - 1 A 1 uf.size(B - 1) uf.size uf size B - 1 B 1 uf.unite(A - 1, B - 1) uf.unite uf unite A - 1 A 1 B - 1 B 1 for a in ans[:-1][::-1]:
    print(a) a ans[:-1][::-1] [:-1] ans :-1 -1 ::-1 -1 print(a) print a M = map(int, input().split()) map(int, input().split()) M uf = UnionFind(N) UnionFind(N) uf N , M = map(int, input().split()) map(int, input().split()) N ans = [N * (N - 1) // 2] [N * (N - 1) // 2] ans AB = [list(map(int, input().split())) for _ in range(M)] [list(map(int, input().split())) for _ in range(M)] AB class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        # 親の番号 根なら要素数(負の数)

    def find(self, x):
        """木の根を求める"""
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        """xとyの属する集合を併合"""
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        """xとyが同じ集合に属するか否か"""
        return self.find(x) == self.find(y)

    def size(self, x):
        """グループのサイズを返す"""
        return -self.parents[self.find(x)] class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        # 親の番号 根なら要素数(負の数)

    def find(self, x):
        """木の根を求める"""
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        """xとyの属する集合を併合"""
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        """xとyが同じ集合に属するか否か"""
        return self.find(x) == self.find(y)

    def size(self, x):
        """グループのサイズを返す"""
        return -self.parents[self.find(x)] UnionFind
import sys
sys.setrecursionlimit(1000000)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        # 親の番号 根なら要素数(負の数)

    def find(self, x):
        """木の根を求める"""
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        """xとyの属する集合を併合"""
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        """xとyが同じ集合に属するか否か"""
        return self.find(x) == self.find(y)

    def size(self, x):
        """グループのサイズを返す"""
        return -self.parents[self.find(x)]

N , M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
uf = UnionFind(N)
AB.reverse()
ans = [N * (N - 1) // 2]
for A, B in AB:
    if uf.same(A - 1, B - 1):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uf.size(A - 1) * uf.size(B - 1))
    uf.unite(A - 1, B - 1)

for a in ans[:-1][::-1]:
    print(a)
