from sys import setrecursionlimit
#setrecursionlimit(10**5)
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納
        # par[x]=xの時そのノードは根　
        self.par = [i for i in range(n + 1)]
        # rank
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        # 根の番号を返す(所属する集合を確認する)
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def check(self, x, y):
        # x,yが同じ集合に属するかどうか調べる
        return self.find(x) == self.find(y)


    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        if x == y:return
        # rankの小さいものを大きいほうにくっつける
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def count_group(self, n):
        return len({self.find(x) for x in range(1, n + 1)})

def com_2(n):
    if n == 1:return 0
    return n * (n - 1) // 2

n, m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
ab = ab[::-1]
uf = UnionFind(n)

rec = [n * (n - 1) // 2] * m
for i in range(m - 1):
    a, b = ab[i]
    if uf.check(a, b):
        rec[i + 1] = rec[i]
        continue
    a_size = uf.size[uf.find(a)]
    b_size = uf.size[uf.find(b)]
    temp = com_2(a_size) + com_2(b_size) - com_2(a_size + b_size)
    rec[i + 1] = rec[i] + temp
    uf.union(a, b)

rec = rec[::-1]
print(*rec, sep='\n') from sys import setrecursionlimit class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納
        # par[x]=xの時そのノードは根　
        self.par = [i for i in range(n + 1)]
        # rank
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        # 根の番号を返す(所属する集合を確認する)
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def check(self, x, y):
        # x,yが同じ集合に属するかどうか調べる
        return self.find(x) == self.find(y)


    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        if x == y:return
        # rankの小さいものを大きいほうにくっつける
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def count_group(self, n):
        return len({self.find(x) for x in range(1, n + 1)}) UnionFind def __init__(self, n):
        # 親要素のノード番号を格納
        # par[x]=xの時そのノードは根　
        self.par = [i for i in range(n + 1)]
        # rank
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

     __init__ i for i in range(n + 1) for i in range(n + 1) i range(n + 1) range n + 1 n 1 for i in range(n + 1) i self.par = [i for i in range(n + 1)] self.par self par [i for i in range(n + 1)] self.rank = [0] * (n + 1) self.rank self rank [0] * (n + 1) [0] 0 n + 1 n 1 self.size = [1] * (n + 1) self.size self size [1] * (n + 1) [1] 1 n + 1 n 1 self self n n def find(self, x):
        # 根の番号を返す(所属する集合を確認する)
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

     find if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

     self.par[x] == x self.par[x] self.par self par x x return x x self.par[x] = self.find(self.par[x]) self.par[x] self.par self par x self.find(self.par[x]) self.find self find self.par[x] self.par self par x return self.par[x] self.par[x] self.par self par x self self x x def check(self, x, y):
        # x,yが同じ集合に属するかどうか調べる
        return self.find(x) == self.find(y)


     check 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 union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        if x == y:return
        # rankの小さいものを大きいほうにくっつける
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

     union 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
        # rankの小さいものを大きいほうにくっつける
         x == y x y if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

     self.rank[x] < self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.par[x] = y self.par[x] self.par self par x y self.size[y] += self.size[x] self.size[y] self.size self size y self.size[x] self.size self size x self.par[y] = x self.par[y] self.par self par y x self.size[x] += self.size[y] self.size[x] self.size self size x self.size[y] self.size self size y if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

     self.rank[x] == self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.rank[x] += 1 self.rank[x] self.rank self rank x 1 self self x x y y def count_group(self, n):
        return len({self.find(x) for x in range(1, n + 1)}) count_group self.find(x) for x in range(1, n + 1) for x in range(1, n + 1) x range(1, n + 1) range 1 n + 1 n 1 for x in range(1, n + 1) self.find(x) self.find self find x return len({self.find(x) for x in range(1, n + 1)}) len({self.find(x) for x in range(1, n + 1)}) len self self n n def com_2(n):
    if n == 1:return 0
    return n * (n - 1) // 2 com_2 if n == 1:return 0
     n == 1 n 1 return n * (n - 1) // 2 n * (n - 1) // 2 n * (n - 1) n n - 1 n 1 2 n n 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 i in range(m) for i in range(m) i range(m) range m for i 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 i in range(m)] ab [list(map(int,input().split())) for i in range(m)] ab = ab[::-1] ab ab[::-1] ab ::-1 -1 uf = UnionFind(n) uf UnionFind(n) UnionFind n rec = [n * (n - 1) // 2] * m rec [n * (n - 1) // 2] * m [n * (n - 1) // 2] n * (n - 1) // 2 n * (n - 1) n n - 1 n 1 2 m for i in range(m - 1):
    a, b = ab[i]
    if uf.check(a, b):
        rec[i + 1] = rec[i]
        continue
    a_size = uf.size[uf.find(a)]
    b_size = uf.size[uf.find(b)]
    temp = com_2(a_size) + com_2(b_size) - com_2(a_size + b_size)
    rec[i + 1] = rec[i] + temp
    uf.union(a, b) i range(m - 1) range m - 1 m 1 a, b = ab[i] a ab[i] ab i b if uf.check(a, b):
        rec[i + 1] = rec[i]
        continue
     uf.check(a, b) uf.check uf check a b rec[i + 1] = rec[i] rec[i + 1] rec i + 1 i 1 rec[i] rec i continue a_size = uf.size[uf.find(a)] a_size uf.size[uf.find(a)] uf.size uf size uf.find(a) uf.find uf find a b_size = uf.size[uf.find(b)] b_size uf.size[uf.find(b)] uf.size uf size uf.find(b) uf.find uf find b temp = com_2(a_size) + com_2(b_size) - com_2(a_size + b_size) temp com_2(a_size) + com_2(b_size) - com_2(a_size + b_size) com_2(a_size) + com_2(b_size) com_2(a_size) com_2 a_size com_2(b_size) com_2 b_size com_2(a_size + b_size) com_2 a_size + b_size a_size b_size rec[i + 1] = rec[i] + temp rec[i + 1] rec i + 1 i 1 rec[i] + temp rec[i] rec i temp uf.union(a, b) uf.union uf union a b rec = rec[::-1] rec rec[::-1] rec ::-1 -1 print(*rec, sep='\n') print *rec rec sep='\n' sep '\n' m = map(int,input().split()) map(int,input().split()) m b_size = uf.size[uf.find(b)] uf.size[uf.find(b)] b_size rec = [n * (n - 1) // 2] * m [n * (n - 1) // 2] * m rec class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納
        # par[x]=xの時そのノードは根　
        self.par = [i for i in range(n + 1)]
        # rank
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        # 根の番号を返す(所属する集合を確認する)
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def check(self, x, y):
        # x,yが同じ集合に属するかどうか調べる
        return self.find(x) == self.find(y)


    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        if x == y:return
        # rankの小さいものを大きいほうにくっつける
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def count_group(self, n):
        return len({self.find(x) for x in range(1, n + 1)}) class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納
        # par[x]=xの時そのノードは根　
        self.par = [i for i in range(n + 1)]
        # rank
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        # 根の番号を返す(所属する集合を確認する)
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def check(self, x, y):
        # x,yが同じ集合に属するかどうか調べる
        return self.find(x) == self.find(y)


    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        if x == y:return
        # rankの小さいものを大きいほうにくっつける
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def count_group(self, n):
        return len({self.find(x) for x in range(1, n + 1)}) UnionFind def com_2(n):
    if n == 1:return 0
    return n * (n - 1) // 2 def com_2(n):
    if n == 1:return 0
    return n * (n - 1) // 2 com_2 n, m = map(int,input().split()) map(int,input().split()) n b = ab[i] ab[i] b ab = [list(map(int,input().split())) for i in range(m)] [list(map(int,input().split())) for i in range(m)] ab ab = ab[::-1] ab[::-1] ab a, b = ab[i] ab[i] a uf = UnionFind(n) UnionFind(n) uf rec = rec[::-1] rec[::-1] rec temp = com_2(a_size) + com_2(b_size) - com_2(a_size + b_size) com_2(a_size) + com_2(b_size) - com_2(a_size + b_size) temp a_size = uf.size[uf.find(a)] uf.size[uf.find(a)] a_size
from sys import setrecursionlimit
#setrecursionlimit(10**5)
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納
        # par[x]=xの時そのノードは根　
        self.par = [i for i in range(n + 1)]
        # rank
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        # 根の番号を返す(所属する集合を確認する)
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def check(self, x, y):
        # x,yが同じ集合に属するかどうか調べる
        return self.find(x) == self.find(y)


    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        if x == y:return
        # rankの小さいものを大きいほうにくっつける
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def count_group(self, n):
        return len({self.find(x) for x in range(1, n + 1)})

def com_2(n):
    if n == 1:return 0
    return n * (n - 1) // 2

n, m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
ab = ab[::-1]
uf = UnionFind(n)

rec = [n * (n - 1) // 2] * m
for i in range(m - 1):
    a, b = ab[i]
    if uf.check(a, b):
        rec[i + 1] = rec[i]
        continue
    a_size = uf.size[uf.find(a)]
    b_size = uf.size[uf.find(b)]
    temp = com_2(a_size) + com_2(b_size) - com_2(a_size + b_size)
    rec[i + 1] = rec[i] + temp
    uf.union(a, b)

rec = rec[::-1]
print(*rec, sep='\n')