import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**6)



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

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



P=list(range(N+1))

C=[1 for _ in range(N+1)]

C[0] = 0



def root(x):

    if P[x]==x: return x

    P[x] = root(P[x])

    return P[x]



def unite(a,b):

    ra = root(a)

    rb = root(b)

    if count(ra) < count(rb): ra,rb = rb,ra

    C[ra] += C[rb]

    C[rb] = 0

    P[rb] = ra



def same(a,b):

    return root(a) == root(b)



def count(x):

    return C[root(x)]



ans=[0]*(M+1)

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



for i in range(M-1,-1,-1):

    a,b = B[i]

    if same(a,b):

        ans[i] = ans[i+1]

        continue

    ans[i] = ans[i+1] - count(a) * count(b)

    unite(a,b)



for i in range(1,M+1):

    print((ans[i]))
import sys

def main():

    input = sys.stdin.readline

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

    AB=[tuple([int(x)-1 for x in input().split()]) for _ in range(M)]



    uf = UnionFindTree(N)

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

    ans = [mx]*M

    for i in range(M-1,0,-1):

        a,b = AB[i]

        ans[i-1] = ans[i] - (0 if uf.same(a, b) else uf.size(a)*uf.size(b))

        uf.union(a, b)



    for a in ans: print(a)



class UnionFindTree:

    def __init__(self, n):

        self.parent = [-1] * n



    def find(self, x):

        p = self.parent

        while p[x] >= 0: x, p[x] = p[x], p[p[x]]

        return x



    def union(self, x, y):

        x, y, p = self.find(x), self.find(y), self.parent

        if x == y: return

        if p[x] > p[y]: x, y = y, x

        p[x], p[y] = p[x] + p[y], x



    def same(self, x, y): return self.find(x) == self.find(y)

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





if __name__ == '__main__':

    main()
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N, M = list(map(int, input().split()))
B = [tuple(map(int, input().split())) for _ in range(M)]
P = list(range(N + 1))
C = [1 for _ in range(N + 1)]
C[0] = 0


def root(x):
    if P[x] == x:
        return x
    P[x] = root(P[x])
    return P[x]


def unite(a, b):
    ra = root(a)
    rb = root(b)
    if count(ra) < count(rb):
        ra, rb = rb, ra
    C[ra] += C[rb]
    C[rb] = 0
    P[rb] = ra


def same(a, b):
    return root(a) == root(b)


def count(x):
    return C[root(x)]


ans = [0] * (M + 1)
ans[M] = N * (N - 1) // 2
for i in range(M - 1, -1, -1):
    a, b = B[i]
    if same(a, b):
        ans[i] = ans[i + 1]
        continue
    ans[i] = ans[i + 1] - count(a) * count(b)
    unite(a, b)
for i in range(1, M + 1):
    print((ans[i]))

import sys


def main():
    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    AB = [tuple([int(x) - 1 for x in input().split()]) for _ in range(M)]
    uf = UnionFindTree(N)
    mx = N * (N - 1) // 2
    ans = [mx] * M
    for i in range(M - 1, 0, -1):
        a, b = AB[i]
        ans[i - 1] = ans[i] - (0 if uf.same(a, b) else uf.size(a) * uf.size(b))
        uf.union(a, b)
    for a in ans:
        print(a)


class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        p = self.parent
        while p[x] >= 0:
            x, p[x] = p[x], p[p[x]]
        return x

    def union(self, x, y):
        x, y, p = self.find(x), self.find(y), self.parent
        if x == y:
            return
        if p[x] > p[y]:
            x, y = y, x
        p[x], p[y] = p[x] + p[y], x

    def same(self, x, y):
        return self.find(x) == self.find(y)

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


if __name__ == "__main__":
    main()

-input = sys.stdin.readline -sys.setrecursionlimit(10**6) -N, M = list(map(int, input().split())) -B = [tuple(map(int, input().split())) for _ in range(M)] -P = list(range(N + 1)) -C = [1 for _ in range(N + 1)] -C[0] = 0 + +def main(): +    input = sys.stdin.readline +    N, M = list(map(int, input().split())) +    AB = [tuple([int(x) - 1 for x in input().split()]) for _ in range(M)] +    uf = UnionFindTree(N) +    mx = N * (N - 1) // 2 +    ans = [mx] * M +    for i in range(M - 1, 0, -1): +        a, b = AB[i] +        ans[i - 1] = ans[i] - (0 if uf.same(a, b) else uf.size(a) * uf.size(b)) +        uf.union(a, b) +    for a in ans: +        print(a) -def root(x): -    if P[x] == x: +class UnionFindTree: +    def __init__(self, n): +        self.parent = [-1] * n + +    def find(self, x): +        p = self.parent +        while p[x] >= 0: +            x, p[x] = p[x], p[p[x]] -    P[x] = root(P[x]) -    return P[x] + +    def union(self, x, y): +        x, y, p = self.find(x), self.find(y), self.parent +        if x == y: +            return +        if p[x] > p[y]: +            x, y = y, x +        p[x], p[y] = p[x] + p[y], x + +    def same(self, x, y): +        return self.find(x) == self.find(y) + +    def size(self, x): +        return -self.parent[self.find(x)] -def unite(a, b): -    ra = root(a) -    rb = root(b) -    if count(ra) < count(rb): -        ra, rb = rb, ra -    C[ra] += C[rb] -    C[rb] = 0 -    P[rb] = ra - - -def same(a, b): -    return root(a) == root(b) - - -def count(x): -    return C[root(x)] - - -ans = [0] * (M + 1) -ans[M] = N * (N - 1) // 2 -for i in range(M - 1, -1, -1): -    a, b = B[i] -    if same(a, b): -        ans[i] = ans[i + 1] -        continue -    ans[i] = ans[i + 1] - count(a) * count(b) -    unite(a, b) -for i in range(1, M + 1): -    print((ans[i])) +if __name__ == "__main__": +    main()