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

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





class UnionFind:

    def __init__(self, n):

        self.n = n

        self.p = [e for e in range(n)]

        self.rank = [0] * n

        self.size = [1] * n



    def same(self, u, v):

        return self.find_set(u) == self.find_set(v)



    def unite(self, u, v):

        self.link(self.find_set(u), self.find_set(v))



    def find_set(self, u):

        if u != self.p[u]:

            self.p[u] = self.find_set(self.p[u])



        return self.p[u]



    def link(self, u, v):

        if self.rank[u] > self.rank[v]:

            self.p[v] = u

            self.size[u] += self.size[v]

        else:

            self.p[u] = v

            self.size[v] += self.size[u]

            if self.rank[u] == self.rank[v]:

                self.rank[v] += 1



    def update_p(self):

        for u in range(self.n):

            self.find_set(u)



    def get_size(self, u):

        return self.size[self.find_set(u)]



    def comb(self, u):

        sz = self.get_size(u)

        return sz * (sz - 1) // 2





uf = UnionFind(n)



ans = [0]

sm = 0

for a, b in ab[-1:0:-1]:

    a -= 1

    b -= 1

    if not uf.same(a, b):

        sm -= uf.comb(a) + uf.comb(b)

        uf.unite(a, b)

        sm += uf.comb(a)

    ans.append(sm)



ans = [n * (n - 1) // 2 - e for e in ans[::-1]]

print(*ans, sep="\n")

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

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





class UnionFind:

    def __init__(self, n):

        self.n = n

        self.p = [e for e in range(n)]

        self.rank = [0] * n

        self.size = [1] * n



    def same(self, u, v):

        return self.find_set(u) == self.find_set(v)



    def unite(self, u, v):

        self.link(self.find_set(u), self.find_set(v))



    def find_set(self, u):

        if u != self.p[u]:

            self.p[u] = self.find_set(self.p[u])



        return self.p[u]



    def link(self, u, v):

        if self.rank[u] > self.rank[v]:

            self.p[v] = u

            self.size[u] += self.size[v]

        else:

            self.p[u] = v

            self.size[v] += self.size[u]

            if self.rank[u] == self.rank[v]:

                self.rank[v] += 1



    def update_p(self):

        for u in range(self.n):

            self.find_set(u)



    def get_size(self, u):

        return self.size[self.find_set(u)]





uf = UnionFind(n)



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

ans = [sm]

for a, b in ab[-1:0:-1]:

    a -= 1

    b -= 1

    if not uf.same(a, b):

        sm -= uf.get_size(a) * uf.get_size(b)

        uf.unite(a, b)

    ans.append(sm)



print(*ans[::-1], sep="\n")

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


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        self.link(self.find_set(u), self.find_set(v))

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])
        return self.p[u]

    def link(self, u, v):
        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)]

    def comb(self, u):
        sz = self.get_size(u)
        return sz * (sz - 1) // 2


uf = UnionFind(n)
ans = [0]
sm = 0
for a, b in ab[-1:0:-1]:
    a -= 1
    b -= 1
    if not uf.same(a, b):
        sm -= uf.comb(a) + uf.comb(b)
        uf.unite(a, b)
        sm += uf.comb(a)
    ans.append(sm)
ans = [n * (n - 1) // 2 - e for e in ans[::-1]]
print(*ans, sep="\n")

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


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        self.link(self.find_set(u), self.find_set(v))

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])
        return self.p[u]

    def link(self, u, v):
        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)]


uf = UnionFind(n)
sm = n * (n - 1) // 2
ans = [sm]
for a, b in ab[-1:0:-1]:
    a -= 1
    b -= 1
    if not uf.same(a, b):
        sm -= uf.get_size(a) * uf.get_size(b)
        uf.unite(a, b)
    ans.append(sm)
print(*ans[::-1], sep="\n")

-    def comb(self, u): -        sz = self.get_size(u) -        return sz * (sz - 1) // 2 - -ans = [0] -sm = 0 +sm = n * (n - 1) // 2 +ans = [sm] -        sm -= uf.comb(a) + uf.comb(b) +        sm -= uf.get_size(a) * uf.get_size(b) -        sm += uf.comb(a) -ans = [n * (n - 1) // 2 - e for e in ans[::-1]] -print(*ans, sep="\n") +print(*ans[::-1], sep="\n")