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

a, b = [], []

for i in range(M):

    a_i, b_i = list(map(int, input().split()))

    a.append(a_i -1)

    b.append(b_i -1)

    

class UnionFind:

    def __init__(self, n):

        self.p = {}

        self.r = {}

        self.s = {}

        for i in range(n):

            self.p[i] = i # 親,グループ番号

            self.r[i] = 1 

            self.s[i] = 1 # サイズ、連結数

            

    def find(self, n):

        path = []

        while n != self.p[n]:

            path.append(n)

            n = self.p[n]

        for m in path:

            self.p[m] = n

        return n 



    def union(self, a, b):

        ap = self.find(a)

        bp = self.find(b)

        if self.r[ap] > self.r[bp]:

            self.p[bp] = ap

            size = self.s[bp] + self.s[ap]

            self.s[ap] = size

        elif self.r[bp] > self.r[ap]:

            self.p[ap] = bp

            size = self.s[bp] + self.s[ap]

            self.s[bp] = size

        elif ap != bp:

            self.p[ap] = bp

            self.r[bp] += 1

            size = self.s[bp] + self.s[ap]

            self.s[bp] = size

            

    def size(self, n):

        np = self.find(n)

        return self.s[np]

    

s = UnionFind(N)

 

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

anss = [ans]



for i in range(M):

    j = M - i - 1

    if s.find(a[j]) != s.find(b[j]):

        ans -= s.size(a[j]) * s.size(b[j])

        s.union(a[j], b[j])

    if i != M-1:

        anss.append(ans)

        

sort_ans = sorted(anss)

for i in range(len(sort_ans)):

    print((sort_ans[i]))
class UnionFind:

    def __init__(self, n):

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

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

            

    def find(self, x):

        if x == self.p[x]:

            return x

        else:

            self.p[x] = self.find(self.p[x])

            return self.p[x]



    def union(self, a, b):

        ap = self.find(a)

        bp = self.find(b)

        if ap != bp:

            mini = min(ap ,bp)

            maxi = max(ap, bp)

            self.p[maxi] = mini

            size = self.s[bp] + self.s[ap]

            self.s[bp] = size

            self.s[ap] = size

            return True

        else:

            return False

            

    def size(self, n):

        np = self.find(n)

        return self.s[np]

    

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

a, b = [], []

for i in range(M):

    a_i, b_i = list(map(int, input().split()))

    a.append(a_i -1)

    b.append(b_i - 1)

    

s = UnionFind(N)

 

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

anss = [ans]

    

for i in range(M):

    j = M - i - 1

    if s.find(a[j]) != s.find(b[j]):

        ans -= s.size(a[j]) * s.size(b[j])

        s.union(a[j], b[j])

    if i != M-1:

        anss.append(ans)

        

sort_ans = sorted(anss)

for i in range(len(sort_ans)):

    print((sort_ans[i]))
N, M = list(map(int, input().split()))
a, b = [], []
for i in range(M):
    a_i, b_i = list(map(int, input().split()))
    a.append(a_i - 1)
    b.append(b_i - 1)


class UnionFind:
    def __init__(self, n):
        self.p = {}
        self.r = {}
        self.s = {}
        for i in range(n):
            self.p[i] = i  # 親,グループ番号
            self.r[i] = 1
            self.s[i] = 1  # サイズ、連結数

    def find(self, n):
        path = []
        while n != self.p[n]:
            path.append(n)
            n = self.p[n]
        for m in path:
            self.p[m] = n
        return n

    def union(self, a, b):
        ap = self.find(a)
        bp = self.find(b)
        if self.r[ap] > self.r[bp]:
            self.p[bp] = ap
            size = self.s[bp] + self.s[ap]
            self.s[ap] = size
        elif self.r[bp] > self.r[ap]:
            self.p[ap] = bp
            size = self.s[bp] + self.s[ap]
            self.s[bp] = size
        elif ap != bp:
            self.p[ap] = bp
            self.r[bp] += 1
            size = self.s[bp] + self.s[ap]
            self.s[bp] = size

    def size(self, n):
        np = self.find(n)
        return self.s[np]


s = UnionFind(N)
ans = (N * (N - 1)) // 2
anss = [ans]
for i in range(M):
    j = M - i - 1
    if s.find(a[j]) != s.find(b[j]):
        ans -= s.size(a[j]) * s.size(b[j])
        s.union(a[j], b[j])
    if i != M - 1:
        anss.append(ans)
sort_ans = sorted(anss)
for i in range(len(sort_ans)):
    print((sort_ans[i]))

class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.s = [1 for i in range(n)]

    def find(self, x):
        if x == self.p[x]:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def union(self, a, b):
        ap = self.find(a)
        bp = self.find(b)
        if ap != bp:
            mini = min(ap, bp)
            maxi = max(ap, bp)
            self.p[maxi] = mini
            size = self.s[bp] + self.s[ap]
            self.s[bp] = size
            self.s[ap] = size
            return True
        else:
            return False

    def size(self, n):
        np = self.find(n)
        return self.s[np]


N, M = list(map(int, input().split()))
a, b = [], []
for i in range(M):
    a_i, b_i = list(map(int, input().split()))
    a.append(a_i - 1)
    b.append(b_i - 1)
s = UnionFind(N)
ans = (N * (N - 1)) // 2
anss = [ans]
for i in range(M):
    j = M - i - 1
    if s.find(a[j]) != s.find(b[j]):
        ans -= s.size(a[j]) * s.size(b[j])
        s.union(a[j], b[j])
    if i != M - 1:
        anss.append(ans)
sort_ans = sorted(anss)
for i in range(len(sort_ans)):
    print((sort_ans[i]))

+class UnionFind: +    def __init__(self, n): +        self.p = [i for i in range(n)] +        self.s = [1 for i in range(n)] + +    def find(self, x): +        if x == self.p[x]: +            return x +        else: +            self.p[x] = self.find(self.p[x]) +            return self.p[x] + +    def union(self, a, b): +        ap = self.find(a) +        bp = self.find(b) +        if ap != bp: +            mini = min(ap, bp) +            maxi = max(ap, bp) +            self.p[maxi] = mini +            size = self.s[bp] + self.s[ap] +            self.s[bp] = size +            self.s[ap] = size +            return True +        else: +            return False + +    def size(self, n): +        np = self.find(n) +        return self.s[np] + + - - -class UnionFind: -    def __init__(self, n): -        self.p = {} -        self.r = {} -        self.s = {} -        for i in range(n): -            self.p[i] = i  # 親,グループ番号 -            self.r[i] = 1 -            self.s[i] = 1  # サイズ、連結数 - -    def find(self, n): -        path = [] -        while n != self.p[n]: -            path.append(n) -            n = self.p[n] -        for m in path: -            self.p[m] = n -        return n - -    def union(self, a, b): -        ap = self.find(a) -        bp = self.find(b) -        if self.r[ap] > self.r[bp]: -            self.p[bp] = ap -            size = self.s[bp] + self.s[ap] -            self.s[ap] = size -        elif self.r[bp] > self.r[ap]: -            self.p[ap] = bp -            size = self.s[bp] + self.s[ap] -            self.s[bp] = size -        elif ap != bp: -            self.p[ap] = bp -            self.r[bp] += 1 -            size = self.s[bp] + self.s[ap] -            self.s[bp] = size - -    def size(self, n): -        np = self.find(n) -        return self.s[np] - -