from collections import deque



class UnionFind:

    def __init__(self, n):

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

        self.rank = [0]*n

        self.size = [1]*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]

    

    def unite(self, x, y):

        x = self.find(x)

        y = self.find(y)

        

        if x == y:

            return

        else:

            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 same_check(self, x, y):

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

    

    def tree_size(self, x):

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

    





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

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

uf = UnionFind(N+1)

anslist = deque()

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

anslist.append(ans)





for i in range(M-1):

    island1 = bridge[M-i-1][0]

    island2 = bridge[M-i-1][1]

    if uf.find(island1) != uf.find(island2):

        ans -= uf.tree_size(island1) * uf.tree_size(island2)

    

    anslist.append(ans)

    uf.unite(bridge[M-i-1][0], bridge[M-i-1][1])



for _ in range(M):

    print((anslist.pop()))
from collections import deque

import sys

input = sys.stdin.readline



class UnionFind:

    def __init__(self, n):

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

        self.rank = [0]*n

        self.size = [1]*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]

    

    def unite(self, x, y):

        x = self.find(x)

        y = self.find(y)

        

        if x == y:

            return

        else:

            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 same_check(self, x, y):

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

    

    def tree_size(self, x):

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

    





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

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

uf = UnionFind(N+1)

anslist = deque()

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

anslist.append(ans)





for i in range(M-1):

    island1 = bridge[M-i-1][0]

    island2 = bridge[M-i-1][1]

    if uf.find(island1) != uf.find(island2):

        ans -= uf.tree_size(island1) * uf.tree_size(island2)

    

    anslist.append(ans)

    uf.unite(bridge[M-i-1][0], bridge[M-i-1][1])



for _ in range(M):

    print((anslist.pop()))
from collections import deque


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * 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]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        else:
            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 same_check(self, x, y):
        return self.find(x) == self.find(y)

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


N, M = list(map(int, input().split()))
bridge = [[int(_) for _ in input().split()] for _ in range(M)]
uf = UnionFind(N + 1)
anslist = deque()
ans = N * (N - 1) // 2
anslist.append(ans)
for i in range(M - 1):
    island1 = bridge[M - i - 1][0]
    island2 = bridge[M - i - 1][1]
    if uf.find(island1) != uf.find(island2):
        ans -= uf.tree_size(island1) * uf.tree_size(island2)
    anslist.append(ans)
    uf.unite(bridge[M - i - 1][0], bridge[M - i - 1][1])
for _ in range(M):
    print((anslist.pop()))

from collections import deque
import sys

input = sys.stdin.readline


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * 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]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        else:
            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 same_check(self, x, y):
        return self.find(x) == self.find(y)

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


N, M = list(map(int, input().split()))
bridge = [[int(_) for _ in input().split()] for _ in range(M)]
uf = UnionFind(N + 1)
anslist = deque()
ans = N * (N - 1) // 2
anslist.append(ans)
for i in range(M - 1):
    island1 = bridge[M - i - 1][0]
    island2 = bridge[M - i - 1][1]
    if uf.find(island1) != uf.find(island2):
        ans -= uf.tree_size(island1) * uf.tree_size(island2)
    anslist.append(ans)
    uf.unite(bridge[M - i - 1][0], bridge[M - i - 1][1])
for _ in range(M):
    print((anslist.pop()))

+import sys + +input = sys.stdin.readline