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

    def root(self, index) :
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

    def getComponent(self) :
        return self.component

N, M = map(int, input().split())
AB = [tuple(map(lambda a: int(a) - 1, input().split())) for _ in range(M)]

tree = UnionFind(N)
now = N * (N - 1) // 2

ans = [now]
for a, b in AB[::-1]:
    if not tree.isSameRoot(a, b):
        now -= tree.sizeOfSameRoot(a) * tree.sizeOfSameRoot(b)
    tree.union(a, b)
    ans.append(now)
print(*ans[::-1][1:], sep='\n') class UnionFind :
    def __init__(self, size) :
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

    def getComponent(self) :
        return self.component UnionFind def __init__(self, size) :
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

     __init__ self.parent = list(range(size)) self.parent self parent list(range(size)) list range(size) range size self.height = [0] * size self.height self height [0] * size [0] 0 size self.size = [1] * size self.size self size [1] * size [1] 1 size self.component = size self.component self component size self self size size def root(self, index) :
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

     root if self.parent[index] == index :  # 根の場合
            return index
         self.parent[index] == index self.parent[index] self.parent self parent index index return index index rootIndex = self.root(self.parent[index]) rootIndex self.root(self.parent[index]) self.root self root self.parent[index] self.parent self parent index self.parent[index] = rootIndex self.parent[index] self.parent self parent index rootIndex return rootIndex rootIndex self self index index def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

     union root1 = self.root(index1) root1 self.root(index1) self.root self root index1 root2 = self.root(index2) root2 self.root(index2) self.root self root index2 if root1 == root2 :  # 連結されている場合
            return

         root1 == root2 root1 root2 return self.component -= 1 self.component self component 1 if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
         self.height[root1] < self.height[root2] self.height[root1] self.height self height root1 self.height[root2] self.height self height root2 self.parent[root1] = root2 self.parent[root1] self.parent self parent root1 root2 self.size[root2] += self.size[root1] self.size[root2] self.size self size root2 self.size[root1] self.size self size root1 self.parent[root2] = root1 self.parent[root2] self.parent self parent root2 root1 self.size[root1] += self.size[root2] self.size[root1] self.size self size root1 self.size[root2] self.size self size root2 if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
         self.height[root1] == self.height[root2] self.height[root1] self.height self height root1 self.height[root2] self.height self height root2 self.height[root1] += 1 self.height[root1] self.height self height root1 1 return self self index1 index1 index2 index2 def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

     isSameRoot return self.root(index1) == self.root(index2) self.root(index1) == self.root(index2) self.root(index1) self.root self root index1 self.root(index2) self.root self root index2 self self index1 index1 index2 index2 def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

     sizeOfSameRoot return self.size[self.root(index)] self.size[self.root(index)] self.size self size self.root(index) self.root self root index self self index index def getComponent(self) :
        return self.component getComponent return self.component self.component self component self self N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M tuple(map(lambda a: int(a) - 1, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) tuple(map(lambda a: int(a) - 1, input().split())) tuple map(lambda a: int(a) - 1, input().split()) map lambda a: int(a) - 1 int(a) - 1 int(a) int a 1 a input().split() ().split () input split AB = [tuple(map(lambda a: int(a) - 1, input().split())) for _ in range(M)] AB [tuple(map(lambda a: int(a) - 1, input().split())) for _ in range(M)] tree = UnionFind(N) tree UnionFind(N) UnionFind N now = N * (N - 1) // 2 now N * (N - 1) // 2 N * (N - 1) N N - 1 N 1 2 ans = [now] ans [now] now for a, b in AB[::-1]:
    if not tree.isSameRoot(a, b):
        now -= tree.sizeOfSameRoot(a) * tree.sizeOfSameRoot(b)
    tree.union(a, b)
    ans.append(now) a b AB[::-1] AB ::-1 -1 if not tree.isSameRoot(a, b):
        now -= tree.sizeOfSameRoot(a) * tree.sizeOfSameRoot(b)
     not tree.isSameRoot(a, b) tree.isSameRoot(a, b) tree.isSameRoot tree isSameRoot a b now -= tree.sizeOfSameRoot(a) * tree.sizeOfSameRoot(b) now tree.sizeOfSameRoot(a) * tree.sizeOfSameRoot(b) tree.sizeOfSameRoot(a) tree.sizeOfSameRoot tree sizeOfSameRoot a tree.sizeOfSameRoot(b) tree.sizeOfSameRoot tree sizeOfSameRoot b tree.union(a, b) tree.union tree union a b ans.append(now) ans.append ans append now print(*ans[::-1][1:], sep='\n') print *ans[::-1][1:] ans[::-1][1:] [::-1] ans ::-1 -1 1: 1 sep='\n' sep '\n' N, M = map(int, input().split()) map(int, input().split()) N class UnionFind :
    def __init__(self, size) :
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

    def getComponent(self) :
        return self.component class UnionFind :
    def __init__(self, size) :
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

    def getComponent(self) :
        return self.component UnionFind tree = UnionFind(N) UnionFind(N) tree M = map(int, input().split()) map(int, input().split()) M now -= tree.sizeOfSameRoot(a) * tree.sizeOfSameRoot(b) tree.sizeOfSameRoot(a) * tree.sizeOfSameRoot(b) now AB = [tuple(map(lambda a: int(a) - 1, input().split())) for _ in range(M)] [tuple(map(lambda a: int(a) - 1, input().split())) for _ in range(M)] AB now = N * (N - 1) // 2 N * (N - 1) // 2 now ans = [now] [now] ans
class UnionFind :
    def __init__(self, size) :
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

    def getComponent(self) :
        return self.component

N, M = map(int, input().split())
AB = [tuple(map(lambda a: int(a) - 1, input().split())) for _ in range(M)]

tree = UnionFind(N)
now = N * (N - 1) // 2

ans = [now]
for a, b in AB[::-1]:
    if not tree.isSameRoot(a, b):
        now -= tree.sizeOfSameRoot(a) * tree.sizeOfSameRoot(b)
    tree.union(a, b)
    ans.append(now)
print(*ans[::-1][1:], sep='\n')