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

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



u = [-1] * (n + 1)



def find(v):

    if u[v] < 0:

        return v

    else:

        return find(u[v])



total = n * (n - 1) // 2

ans = [total]



for a, b in reversed(ab[1:]):

    af = find(a)

    bf = find(b)

    af, bf =sorted([af, bf])

    if af != bf:

        total -= u[af] * u[bf]

        u[af] += u[bf]

        u[bf] = af

    ans.append(total)



for a in reversed(ans):

    print(a)
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, *X = list(map(int,open(0).read().split()))



uf = UnionFind(N + 1)



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

r = [S]



while X:

  b, a = X.pop(), X.pop()

  if not uf.same(a, b):

    S -= uf.size(a) * uf.size(b)

  r.append(S)

  uf.union(a, b)



for a in r[-2::-1]:

  print(a)
n, m = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(m)]
u = [-1] * (n + 1)


def find(v):
    if u[v] < 0:
        return v
    else:
        return find(u[v])


total = n * (n - 1) // 2
ans = [total]
for a, b in reversed(ab[1:]):
    af = find(a)
    bf = find(b)
    af, bf = sorted([af, bf])
    if af != bf:
        total -= u[af] * u[bf]
        u[af] += u[bf]
        u[bf] = af
    ans.append(total)
for a in reversed(ans):
    print(a)

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, *X = list(map(int, open(0).read().split()))
uf = UnionFind(N + 1)
S = N * (N - 1) // 2
r = [S]
while X:
    b, a = X.pop(), X.pop()
    if not uf.same(a, b):
        S -= uf.size(a) * uf.size(b)
    r.append(S)
    uf.union(a, b)
for a in r[-2::-1]:
    print(a)

-n, m = list(map(int, input().split())) -ab = [tuple(map(int, input().split())) for _ in range(m)] -u = [-1] * (n + 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) -def find(v): -    if u[v] < 0: -        return v -    else: -        return find(u[v]) - - -total = n * (n - 1) // 2 -ans = [total] -for a, b in reversed(ab[1:]): -    af = find(a) -    bf = find(b) -    af, bf = sorted([af, bf]) -    if af != bf: -        total -= u[af] * u[bf] -        u[af] += u[bf] -        u[bf] = af -    ans.append(total) -for a in reversed(ans): +N, M, *X = list(map(int, open(0).read().split())) +uf = UnionFind(N + 1) +S = N * (N - 1) // 2 +r = [S] +while X: +    b, a = X.pop(), X.pop() +    if not uf.same(a, b): +        S -= uf.size(a) * uf.size(b) +    r.append(S) +    uf.union(a, b) +for a in r[-2::-1]: