from collections import Counter, defaultdict, deque



class UnionFind(object):

    """Union find tree."""

    def __init__(self, nodes):

        self.par = list(range(nodes + 1))

        self.sizes = [1] * (nodes + 1)



    def root(self, key):

        if key != self.par[key]:

            k0 = key

            while k0 != self.par[k0]:

                k0 = self.par[k0]

            self.par[key] = k0

        return self.par[key]



    def merge(self, a, b):

        ra = self.root(a)

        rb = self.root(b)

        if ra != rb:

            sa = self.sizes[ra]

            sb = self.sizes[rb]

            self.par[ra] = rb

            self.sizes[rb] += sa

            return sa * sb

        return 0



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

AB = []

for _ in range(M):

    AB.append(list(map(int, input().split())))



uni = UnionFind(N)

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

anses = [comb]

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

    red = uni.merge(a, b)

    comb -= red

    anses.append(comb)



for ans in reversed(anses):

    print(ans)
from collections import Counter, defaultdict, deque



class UnionFind(object):

    """Union find tree."""

    def __init__(self, nodes):

        self.par = [-1] * nodes



    def root(self, key):

        if self.par[key] < 0:

            return key

        self.par[key] = self.root(self.par[key])

        return self.par[key]



    def size(self, key):

        return -self.par[self.root(key)]



    def merge(self, a, b):

        a = self.root(a)

        b = self.root(b)

        if a == b:

            return

        if self.size(a) < self.size(b):

            a, b = b, a

        self.par[a] += self.par[b]

        self.par[b] = a



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

AB = []

for _ in range(M):

    a, b = map(int, input().split())

    a -= 1

    b -= 1

    AB.append([a, b])



uni = UnionFind(N)

ans = [0] * M

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

for i, (a, b) in enumerate(AB[-1:0:-1], 1):

    ans[-i - 1] = ans[-i]

    if uni.root(a) != uni.root(b):

        ans[-i - 1] -= uni.size(a) * uni.size(b)

        uni.merge(a, b)



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

from collections import Counter, defaultdict, deque


class UnionFind(object):
    """Union find tree."""

    def __init__(self, nodes):
        self.par = list(range(nodes + 1))
        self.sizes = [1] * (nodes + 1)

    def root(self, key):
        if key != self.par[key]:
            k0 = key
            while k0 != self.par[k0]:
                k0 = self.par[k0]
            self.par[key] = k0
        return self.par[key]

    def merge(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra != rb:
            sa = self.sizes[ra]
            sb = self.sizes[rb]
            self.par[ra] = rb
            self.sizes[rb] += sa
            return sa * sb
        return 0


N, M = list(map(int, input().split()))
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
uni = UnionFind(N)
comb = N * (N - 1) // 2
anses = [comb]
for a, b in AB[-1:0:-1]:
    red = uni.merge(a, b)
    comb -= red
    anses.append(comb)
for ans in reversed(anses):
    print(ans)

from collections import Counter, defaultdict, deque


class UnionFind(object):
    """Union find tree."""

    def __init__(self, nodes):
        self.par = [-1] * nodes

    def root(self, key):
        if self.par[key] < 0:
            return key
        self.par[key] = self.root(self.par[key])
        return self.par[key]

    def size(self, key):
        return -self.par[self.root(key)]

    def merge(self, a, b):
        a = self.root(a)
        b = self.root(b)
        if a == b:
            return
        if self.size(a) < self.size(b):
            a, b = b, a
        self.par[a] += self.par[b]
        self.par[b] = a


N, M = map(int, input().split())
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    AB.append([a, b])
uni = UnionFind(N)
ans = [0] * M
ans[-1] = N * (N - 1) // 2
for i, (a, b) in enumerate(AB[-1:0:-1], 1):
    ans[-i - 1] = ans[-i]
    if uni.root(a) != uni.root(b):
        ans[-i - 1] -= uni.size(a) * uni.size(b)
        uni.merge(a, b)
print(*ans, sep="\n")

-        self.par = list(range(nodes + 1)) -        self.sizes = [1] * (nodes + 1) +        self.par = [-1] * nodes -        if key != self.par[key]: -            k0 = key -            while k0 != self.par[k0]: -                k0 = self.par[k0] -            self.par[key] = k0 +        if self.par[key] < 0: +            return key +        self.par[key] = self.root(self.par[key]) +    def size(self, key): +        return -self.par[self.root(key)] + -        ra = self.root(a) -        rb = self.root(b) -        if ra != rb: -            sa = self.sizes[ra] -            sb = self.sizes[rb] -            self.par[ra] = rb -            self.sizes[rb] += sa -            return sa * sb -        return 0 +        a = self.root(a) +        b = self.root(b) +        if a == b: +            return +        if self.size(a) < self.size(b): +            a, b = b, a +        self.par[a] += self.par[b] +        self.par[b] = a -N, M = list(map(int, input().split())) +N, M = map(int, input().split()) -    AB.append(list(map(int, input().split()))) +    a, b = map(int, input().split()) +    a -= 1 +    b -= 1 +    AB.append([a, b]) -comb = N * (N - 1) // 2 -anses = [comb] -for a, b in AB[-1:0:-1]: -    red = uni.merge(a, b) -    comb -= red -    anses.append(comb) -for ans in reversed(anses): -    print(ans) +ans = [0] * M +ans[-1] = N * (N - 1) // 2 +for i, (a, b) in enumerate(AB[-1:0:-1], 1): +    ans[-i - 1] = ans[-i] +    if uni.root(a) != uni.root(b): +        ans[-i - 1] -= uni.size(a) * uni.size(b) +        uni.merge(a, b) +print(*ans, sep="\n")