import sys

sys.setrecursionlimit(10**6)





class UnionFind:

    def __init__(self, num):

        self.parent = list(range(num))

        self.size = [1] * num



    def get_root(self, node):

        root = self.parent[node]

        if root == node:

            return root

        else:

            root = self.get_root(root)

            self.parent[node] = root

            return root



    def are_in_same_union(self, node1, node2):

        root1 = self.get_root(node1)

        root2 = self.get_root(node2)

        if root1 == root2:

            return True

        else:

            return False



    def combine(self, node1, node2):

        root1 = self.get_root(node1)

        root2 = self.get_root(node2)

        self.parent[root2] = root1

        self.size[root1] += self.size[root2]





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

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

pairs = pairs[::-1]

answers = []

UF = UnionFind(n+1)

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

answers.append(ans)



for land1, land2 in pairs:

    if UF.are_in_same_union(land1, land2):

        ans = ans

    else:

        root1, root2 = UF.get_root(land1), UF.get_root(land2)

        ans -= UF.size[root1] * UF.size[root2]

        UF.combine(land1, land2)

    answers.append(ans)



answers.pop()

answers = answers[::-1]



for x in answers:

    print(x)



import sys

input = sys.stdin.readline





class UnionFind:

    def __init__(self, size):

        self.parent = [-1] * size

        self.rank = [1] * size

        self.groups = size



    def get_root(self, node):

        parent = self.parent[node]

        if parent == -1:

            root = node

        else:

            root = self.get_root(parent)

            self.parent[node] = root  # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく

        return root



    def in_same_group(self, node1, node2):

        root1 = self.get_root(node1)

        root2 = self.get_root(node2)

        return root1 == root2



    def unite(self, node1, node2):

        if self.in_same_group(node1, node2):

            return

        main_root = self.get_root(node1)

        sub_root = self.get_root(node2)

        if self.rank[main_root] < self.rank[sub_root]:  # rankの大きい方をmain_rootにする

            main_root, sub_root = sub_root, main_root



        self.parent[sub_root] = main_root

        self.rank[main_root] += self.rank[sub_root]

        self.groups -= 1





def main():

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

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

    uf = UnionFind(n)

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

    ans = [inconvenience]



    for a, b in bridges[::-1]:

        if uf.in_same_group(a-1, b-1):

            ans.append(inconvenience)

            continue

        root1 = uf.get_root(a-1)

        root2 = uf.get_root(b-1)

        pattern = uf.rank[root1] * uf.rank[root2]

        inconvenience -= pattern

        ans.append(inconvenience)

        uf.unite(root1, root2)

    ans.pop()

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





if __name__ == "__main__":

    main()

import sys

sys.setrecursionlimit(10**6)


class UnionFind:
    def __init__(self, num):
        self.parent = list(range(num))
        self.size = [1] * num

    def get_root(self, node):
        root = self.parent[node]
        if root == node:
            return root
        else:
            root = self.get_root(root)
            self.parent[node] = root
            return root

    def are_in_same_union(self, node1, node2):
        root1 = self.get_root(node1)
        root2 = self.get_root(node2)
        if root1 == root2:
            return True
        else:
            return False

    def combine(self, node1, node2):
        root1 = self.get_root(node1)
        root2 = self.get_root(node2)
        self.parent[root2] = root1
        self.size[root1] += self.size[root2]


n, m = list(map(int, input().split()))
pairs = [list(map(int, input().split())) for _ in range(m)]
pairs = pairs[::-1]
answers = []
UF = UnionFind(n + 1)
ans = n * (n - 1) // 2
answers.append(ans)
for land1, land2 in pairs:
    if UF.are_in_same_union(land1, land2):
        ans = ans
    else:
        root1, root2 = UF.get_root(land1), UF.get_root(land2)
        ans -= UF.size[root1] * UF.size[root2]
        UF.combine(land1, land2)
    answers.append(ans)
answers.pop()
answers = answers[::-1]
for x in answers:
    print(x)

import sys

input = sys.stdin.readline


class UnionFind:
    def __init__(self, size):
        self.parent = [-1] * size
        self.rank = [1] * size
        self.groups = size

    def get_root(self, node):
        parent = self.parent[node]
        if parent == -1:
            root = node
        else:
            root = self.get_root(parent)
            self.parent[node] = root  # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく
        return root

    def in_same_group(self, node1, node2):
        root1 = self.get_root(node1)
        root2 = self.get_root(node2)
        return root1 == root2

    def unite(self, node1, node2):
        if self.in_same_group(node1, node2):
            return
        main_root = self.get_root(node1)
        sub_root = self.get_root(node2)
        if self.rank[main_root] < self.rank[sub_root]:  # rankの大きい方をmain_rootにする
            main_root, sub_root = sub_root, main_root
        self.parent[sub_root] = main_root
        self.rank[main_root] += self.rank[sub_root]
        self.groups -= 1


def main():
    n, m = map(int, input().split())
    bridges = [list(map(int, input().split())) for _ in range(m)]
    uf = UnionFind(n)
    inconvenience = n * (n - 1) // 2
    ans = [inconvenience]
    for a, b in bridges[::-1]:
        if uf.in_same_group(a - 1, b - 1):
            ans.append(inconvenience)
            continue
        root1 = uf.get_root(a - 1)
        root2 = uf.get_root(b - 1)
        pattern = uf.rank[root1] * uf.rank[root2]
        inconvenience -= pattern
        ans.append(inconvenience)
        uf.unite(root1, root2)
    ans.pop()
    print(*ans[::-1], sep="\n")


if __name__ == "__main__":
    main()

-sys.setrecursionlimit(10**6) +input = sys.stdin.readline -    def __init__(self, num): -        self.parent = list(range(num)) -        self.size = [1] * num +    def __init__(self, size): +        self.parent = [-1] * size +        self.rank = [1] * size +        self.groups = size -        root = self.parent[node] -        if root == node: -            return root +        parent = self.parent[node] +        if parent == -1: +            root = node -            root = self.get_root(root) -            self.parent[node] = root -            return root +            root = self.get_root(parent) +            self.parent[node] = root  # 同じnodeへの2回目以降のget_rootを高速にするために、直接rootに繋いでおく +        return root -    def are_in_same_union(self, node1, node2): +    def in_same_group(self, node1, node2): -        if root1 == root2: -            return True -        else: -            return False +        return root1 == root2 -    def combine(self, node1, node2): -        root1 = self.get_root(node1) -        root2 = self.get_root(node2) -        self.parent[root2] = root1 -        self.size[root1] += self.size[root2] +    def unite(self, node1, node2): +        if self.in_same_group(node1, node2): +            return +        main_root = self.get_root(node1) +        sub_root = self.get_root(node2) +        if self.rank[main_root] < self.rank[sub_root]:  # rankの大きい方をmain_rootにする +            main_root, sub_root = sub_root, main_root +        self.parent[sub_root] = main_root +        self.rank[main_root] += self.rank[sub_root] +        self.groups -= 1 -n, m = list(map(int, input().split())) -pairs = [list(map(int, input().split())) for _ in range(m)] -pairs = pairs[::-1] -answers = [] -UF = UnionFind(n + 1) -ans = n * (n - 1) // 2 -answers.append(ans) -for land1, land2 in pairs: -    if UF.are_in_same_union(land1, land2): -        ans = ans -    else: -        root1, root2 = UF.get_root(land1), UF.get_root(land2) -        ans -= UF.size[root1] * UF.size[root2] -        UF.combine(land1, land2) -    answers.append(ans) -answers.pop() -answers = answers[::-1] -for x in answers: -    print(x) +def main(): +    n, m = map(int, input().split()) +    bridges = [list(map(int, input().split())) for _ in range(m)] +    uf = UnionFind(n) +    inconvenience = n * (n - 1) // 2 +    ans = [inconvenience] +    for a, b in bridges[::-1]: +        if uf.in_same_group(a - 1, b - 1): +            ans.append(inconvenience) +            continue +        root1 = uf.get_root(a - 1) +        root2 = uf.get_root(b - 1) +        pattern = uf.rank[root1] * uf.rank[root2] +        inconvenience -= pattern +        ans.append(inconvenience) +        uf.unite(root1, root2) +    ans.pop() +    print(*ans[::-1], sep="\n") + + +if __name__ == "__main__": +    main()