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 input = sys.stdin.readline input sys.stdin.readline sys.stdin 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 UnionFind def __init__(self, size):
        self.parent = [-1] * size
        self.rank = [1] * size
        self.groups = size

     __init__ self.parent = [-1] * size self.parent self parent [-1] * size [-1] -1 size self.rank = [1] * size self.rank self rank [1] * size [1] 1 size self.groups = size self.groups self groups size self self size 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

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

     in_same_group root1 = self.get_root(node1) root1 self.get_root(node1) self.get_root self get_root node1 root2 = self.get_root(node2) root2 self.get_root(node2) self.get_root self get_root node2 return root1 == root2 root1 == root2 root1 root2 self self node1 node1 node2 node2 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 unite if self.in_same_group(node1, node2):
            return
         self.in_same_group(node1, node2) self.in_same_group self in_same_group node1 node2 return main_root = self.get_root(node1) main_root self.get_root(node1) self.get_root self get_root node1 sub_root = self.get_root(node2) sub_root self.get_root(node2) self.get_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.rank[main_root] < self.rank[sub_root] self.rank[main_root] self.rank self rank main_root self.rank[sub_root] self.rank self rank sub_root main_root, sub_root = sub_root, main_root main_root sub_root sub_root main_root self.parent[sub_root] = main_root self.parent[sub_root] self.parent self parent sub_root main_root self.rank[main_root] += self.rank[sub_root] self.rank[main_root] self.rank self rank main_root self.rank[sub_root] self.rank self rank sub_root self.groups -= 1 self.groups self groups 1 self self node1 node1 node2 node2 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") main n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bridges = [list(map(int, input().split())) for _ in range(m)] bridges [list(map(int, input().split())) for _ in range(m)] uf = UnionFind(n) uf UnionFind(n) UnionFind n inconvenience = n * (n-1) // 2 inconvenience n * (n-1) // 2 n * (n-1) n n-1 n 1 2 ans = [inconvenience] ans [inconvenience] 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)
     a b bridges[::-1] bridges ::-1 -1 if uf.in_same_group(a-1, b-1):
            ans.append(inconvenience)
            continue
         uf.in_same_group(a-1, b-1) uf.in_same_group uf in_same_group a-1 a 1 b-1 b 1 ans.append(inconvenience) ans.append ans append inconvenience continue root1 = uf.get_root(a-1) root1 uf.get_root(a-1) uf.get_root uf get_root a-1 a 1 root2 = uf.get_root(b-1) root2 uf.get_root(b-1) uf.get_root uf get_root b-1 b 1 pattern = uf.rank[root1] * uf.rank[root2] pattern uf.rank[root1] * uf.rank[root2] uf.rank[root1] uf.rank uf rank root1 uf.rank[root2] uf.rank uf rank root2 inconvenience -= pattern inconvenience pattern ans.append(inconvenience) ans.append ans append inconvenience uf.unite(root1, root2) uf.unite uf unite root1 root2 ans.pop() ans.pop ans pop print(*ans[::-1], sep="\n") print *ans[::-1] ans[::-1] ans ::-1 -1 sep="\n" sep "\n" if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main 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") 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") main input = sys.stdin.readline sys.stdin.readline input 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 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 UnionFind
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()
