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 union(self, 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 size(self, x):

        return -self.parents[self.find(x)]



    def same(self, x, y):

        return self.find(x) == self.find(y)



n,m = list(map(int,input().split()))

Bridge = [list(map(int,input().split())) for i in range(m)]



uf = UnionFind(n)



Inconvenience = [n*(n-1)//2]



for b in reversed(Bridge):

  if not uf.same(b[0]-1,b[1]-1):

    Inconvenience += [Inconvenience[-1]-uf.size(b[0]-1)*uf.size(b[1]-1)]

    uf.union(b[0]-1,b[1]-1)

  else:

    Inconvenience += [Inconvenience[-1]]

    

Inconvenience.pop()

for i in reversed(Inconvenience):

  print(i)
class UnionFind():

    def __init__(self, n):

        self.n = n

        self.parents = [i for i in range(n)]

        self.rank = [0 for _ in range(n)]

        self.size = [1 for _ in range(n)]



    def find(self, x):

        root = x

        while self.parents[root] != root:

            root = self.parents[root]

        while self.parents[x] != root:

            parent = self.parents[x]

            self.parents[x] = root

            x = parent

        return root



    def unite(self, x, y):

        xroot = self.find(x)

        yroot = self.find(y)

        if xroot == yroot:

            return

        xrank = self.rank[xroot]

        yrank = self.rank[yroot]

        if xrank < yrank:

            self.parents[xroot] = yroot

            self.size[yroot] += self.size[xroot]

        elif xrank == yrank:

            self.parents[yroot] = xroot

            self.rank[yroot] += 1

            self.size[xroot] += self.size[yroot]

        else:

            self.parents[yroot] = xroot

            self.size[xroot] += self.size[yroot]



    def len(self, x):

        return self.size[self.find(x)]





import sys

input = sys.stdin.readline



N, M = list(map(int, input().split()))

bridge = [tuple(map(int, input().split())) for _ in range(M)]



uf = UnionFind(N)

inc = N * (N - 1) // 2

ans = [inc]



for a, b in reversed(bridge):

    if uf.find(a - 1) != uf.find(b - 1):

        la = uf.len(a - 1)

        lb = uf.len(b - 1)

        uf.unite(a - 1, b - 1)

        lab = uf.len(a - 1)

        inc += la * (la - 1) // 2 + lb * (lb - 1) // 2 - lab * (lab - 1) // 2

    ans.append(inc)



print(('\n'.join(map(str, ans[:-1][::-1]))))
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 union(self, 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 size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)


n, m = list(map(int, input().split()))
Bridge = [list(map(int, input().split())) for i in range(m)]
uf = UnionFind(n)
Inconvenience = [n * (n - 1) // 2]
for b in reversed(Bridge):
    if not uf.same(b[0] - 1, b[1] - 1):
        Inconvenience += [Inconvenience[-1] - uf.size(b[0] - 1) * uf.size(b[1] - 1)]
        uf.union(b[0] - 1, b[1] - 1)
    else:
        Inconvenience += [Inconvenience[-1]]
Inconvenience.pop()
for i in reversed(Inconvenience):
    print(i)

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        root = x
        while self.parents[root] != root:
            root = self.parents[root]
        while self.parents[x] != root:
            parent = self.parents[x]
            self.parents[x] = root
            x = parent
        return root

    def unite(self, x, y):
        xroot = self.find(x)
        yroot = self.find(y)
        if xroot == yroot:
            return
        xrank = self.rank[xroot]
        yrank = self.rank[yroot]
        if xrank < yrank:
            self.parents[xroot] = yroot
            self.size[yroot] += self.size[xroot]
        elif xrank == yrank:
            self.parents[yroot] = xroot
            self.rank[yroot] += 1
            self.size[xroot] += self.size[yroot]
        else:
            self.parents[yroot] = xroot
            self.size[xroot] += self.size[yroot]

    def len(self, x):
        return self.size[self.find(x)]


import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
bridge = [tuple(map(int, input().split())) for _ in range(M)]
uf = UnionFind(N)
inc = N * (N - 1) // 2
ans = [inc]
for a, b in reversed(bridge):
    if uf.find(a - 1) != uf.find(b - 1):
        la = uf.len(a - 1)
        lb = uf.len(b - 1)
        uf.unite(a - 1, b - 1)
        lab = uf.len(a - 1)
        inc += la * (la - 1) // 2 + lb * (lb - 1) // 2 - lab * (lab - 1) // 2
    ans.append(inc)
print(("\n".join(map(str, ans[:-1][::-1]))))

-        self.parents = [-1] * n +        self.parents = [i for i in range(n)] +        self.rank = [0 for _ in range(n)] +        self.size = [1 for _ in range(n)] -        if self.parents[x] < 0: -            return x +        root = x +        while self.parents[root] != root: +            root = self.parents[root] +        while self.parents[x] != root: +            parent = self.parents[x] +            self.parents[x] = root +            x = parent +        return root + +    def unite(self, x, y): +        xroot = self.find(x) +        yroot = self.find(y) +        if xroot == yroot: +            return +        xrank = self.rank[xroot] +        yrank = self.rank[yroot] +        if xrank < yrank: +            self.parents[xroot] = yroot +            self.size[yroot] += self.size[xroot] +        elif xrank == yrank: +            self.parents[yroot] = xroot +            self.rank[yroot] += 1 +            self.size[xroot] += self.size[yroot] -            self.parents[x] = self.find(self.parents[x]) -            return self.parents[x] +            self.parents[yroot] = xroot +            self.size[xroot] += self.size[yroot] -    def union(self, 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 size(self, x): -        return -self.parents[self.find(x)] - -    def same(self, x, y): -        return self.find(x) == self.find(y) +    def len(self, x): +        return self.size[self.find(x)] -n, m = list(map(int, input().split())) -Bridge = [list(map(int, input().split())) for i in range(m)] -uf = UnionFind(n) -Inconvenience = [n * (n - 1) // 2] -for b in reversed(Bridge): -    if not uf.same(b[0] - 1, b[1] - 1): -        Inconvenience += [Inconvenience[-1] - uf.size(b[0] - 1) * uf.size(b[1] - 1)] -        uf.union(b[0] - 1, b[1] - 1) -    else: -        Inconvenience += [Inconvenience[-1]] -Inconvenience.pop() -for i in reversed(Inconvenience): -    print(i) +import sys + +input = sys.stdin.readline +N, M = list(map(int, input().split())) +bridge = [tuple(map(int, input().split())) for _ in range(M)] +uf = UnionFind(N) +inc = N * (N - 1) // 2 +ans = [inc] +for a, b in reversed(bridge): +    if uf.find(a - 1) != uf.find(b - 1): +        la = uf.len(a - 1) +        lb = uf.len(b - 1) +        uf.unite(a - 1, b - 1) +        lab = uf.len(a - 1) +        inc += la * (la - 1) // 2 + lb * (lb - 1) // 2 - lab * (lab - 1) // 2 +    ans.append(inc) +print(("\n".join(map(str, ans[:-1][::-1]))))