import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.parent = [i for i in range(n_nodes)]
        self.rank = [1] * n_nodes
        self.size = [1] * n_nodes

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.size[x] += self.size[y]
        else:
            self.parent[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

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

    def get_parent_list(self):
        return [i for i in range(self.n_nodes) if self.find(i) == i]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()}


def main():
    N, M = map(int, input().split())
    Bridge = [list(map(int, input().split())) for _ in range(M)]
    answer = [N * (N - 1) // 2]
    UF = UnionFind(N)
    for i in range(M):
        AB = Bridge[M - i - 1]
        A = AB[0] - 1
        B = AB[1] - 1
        if UF.check(A, B):
            last = answer[-1]
            answer.append(last)
            continue
        else:
            before = UF.size[UF.find(A)]
            UF.unite(AB[0] - 1, AB[1] - 1)
            after = UF.size[UF.find(A)]
            last = answer[-1]
            if before == after:
                answer.append(last)
            else:
                answer.append(last - (after - before) * before)

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


if __name__ == "__main__":
    main() import sys sys def input():
    return sys.stdin.readline().strip() input return sys.stdin.readline().strip() sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip sys.setrecursionlimit(20000000) sys.setrecursionlimit sys setrecursionlimit 20000000 class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.parent = [i for i in range(n_nodes)]
        self.rank = [1] * n_nodes
        self.size = [1] * n_nodes

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.size[x] += self.size[y]
        else:
            self.parent[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

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

    def get_parent_list(self):
        return [i for i in range(self.n_nodes) if self.find(i) == i]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()} UnionFind def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.parent = [i for i in range(n_nodes)]
        self.rank = [1] * n_nodes
        self.size = [1] * n_nodes

     __init__ self.n_nodes = n_nodes self.n_nodes self n_nodes n_nodes i for i in range(n_nodes) for i in range(n_nodes) i range(n_nodes) range n_nodes for i in range(n_nodes) i self.parent = [i for i in range(n_nodes)] self.parent self parent [i for i in range(n_nodes)] self.rank = [1] * n_nodes self.rank self rank [1] * n_nodes [1] 1 n_nodes self.size = [1] * n_nodes self.size self size [1] * n_nodes [1] 1 n_nodes self self n_nodes n_nodes def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

     find if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

     self.parent[x] == x self.parent[x] self.parent self parent x x return x x self.parent[x] = self.find(self.parent[x]) self.parent[x] self.parent self parent x self.find(self.parent[x]) self.find self find self.parent[x] self.parent self parent x return self.parent[x] self.parent[x] self.parent self parent x self self x x def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.size[x] += self.size[y]
        else:
            self.parent[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

     unite x = self.find(x) x self.find(x) self.find self find x y = self.find(y) y self.find(y) self.find self find y if x == y:
            return
         x == y x y return if self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.size[x] += self.size[y]
        else:
            self.parent[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

     self.rank[x] > self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.parent[y] = x self.parent[y] self.parent self parent y x self.size[x] += self.size[y] self.size[x] self.size self size x self.size[y] self.size self size y self.parent[x] = y self.parent[x] self.parent self parent x y self.size[y] += self.size[x] self.size[y] self.size self size y self.size[x] self.size self size x if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

     self.rank[x] == self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.rank[y] += 1 self.rank[y] self.rank self rank y 1 self self x x y y def check(self, x, y):
        return self.find(x) == self.find(y)

     check return self.find(x) == self.find(y) self.find(x) == self.find(y) self.find(x) self.find self find x self.find(y) self.find self find y self self x x y y def get_parent_list(self):
        return [i for i in range(self.n_nodes) if self.find(i) == i]

     get_parent_list i for i in range(self.n_nodes) if self.find(i) == i for i in range(self.n_nodes) if self.find(i) == i i range(self.n_nodes) range self.n_nodes self n_nodes self.find(i) == i self.find(i) self.find self find i i if self.find(i) == i i return [i for i in range(self.n_nodes) if self.find(i) == i] [i for i in range(self.n_nodes) if self.find(i) == i] self self def get_n_groups(self):
        return len(self.get_parent_list())

     get_n_groups return len(self.get_parent_list()) len(self.get_parent_list()) len self.get_parent_list() self.get_parent_list self get_parent_list self self def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

     get_members parent = self.find(x) parent self.find(x) self.find self find x i for i in range(self.n_nodes) if self.find(i) == parent for i in range(self.n_nodes) if self.find(i) == parent i range(self.n_nodes) range self.n_nodes self n_nodes self.find(i) == parent self.find(i) self.find self find i parent if self.find(i) == parent i return [i for i in range(self.n_nodes) if self.find(i) == parent] [i for i in range(self.n_nodes) if self.find(i) == parent] self self x x def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()} get_members_dict par: self.get_members(par) for par in self.get_parent_list() for par in self.get_parent_list() par self.get_parent_list() self.get_parent_list self get_parent_list for par in self.get_parent_list() par self.get_members(par) self.get_members self get_members par return {par: self.get_members(par) for par in self.get_parent_list()} {par: self.get_members(par) for par in self.get_parent_list()} self self def main():
    N, M = map(int, input().split())
    Bridge = [list(map(int, input().split())) for _ in range(M)]
    answer = [N * (N - 1) // 2]
    UF = UnionFind(N)
    for i in range(M):
        AB = Bridge[M - i - 1]
        A = AB[0] - 1
        B = AB[1] - 1
        if UF.check(A, B):
            last = answer[-1]
            answer.append(last)
            continue
        else:
            before = UF.size[UF.find(A)]
            UF.unite(AB[0] - 1, AB[1] - 1)
            after = UF.size[UF.find(A)]
            last = answer[-1]
            if before == after:
                answer.append(last)
            else:
                answer.append(last - (after - before) * before)

    answer = answer[::-1]
    print(*answer[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 Bridge = [list(map(int, input().split())) for _ in range(M)] Bridge [list(map(int, input().split())) for _ in range(M)] answer = [N * (N - 1) // 2] answer [N * (N - 1) // 2] N * (N - 1) // 2 N * (N - 1) N N - 1 N 1 2 UF = UnionFind(N) UF UnionFind(N) UnionFind N for i in range(M):
        AB = Bridge[M - i - 1]
        A = AB[0] - 1
        B = AB[1] - 1
        if UF.check(A, B):
            last = answer[-1]
            answer.append(last)
            continue
        else:
            before = UF.size[UF.find(A)]
            UF.unite(AB[0] - 1, AB[1] - 1)
            after = UF.size[UF.find(A)]
            last = answer[-1]
            if before == after:
                answer.append(last)
            else:
                answer.append(last - (after - before) * before)

     i range(M) range M AB = Bridge[M - i - 1] AB Bridge[M - i - 1] Bridge M - i - 1 M - i M i 1 A = AB[0] - 1 A AB[0] - 1 AB[0] AB 0 1 B = AB[1] - 1 B AB[1] - 1 AB[1] AB 1 1 if UF.check(A, B):
            last = answer[-1]
            answer.append(last)
            continue
        else:
            before = UF.size[UF.find(A)]
            UF.unite(AB[0] - 1, AB[1] - 1)
            after = UF.size[UF.find(A)]
            last = answer[-1]
            if before == after:
                answer.append(last)
            else:
                answer.append(last - (after - before) * before)

     UF.check(A, B) UF.check UF check A B last = answer[-1] last answer[-1] answer -1 answer.append(last) answer.append answer append last continue before = UF.size[UF.find(A)] before UF.size[UF.find(A)] UF.size UF size UF.find(A) UF.find UF find A UF.unite(AB[0] - 1, AB[1] - 1) UF.unite UF unite AB[0] - 1 AB[0] AB 0 1 AB[1] - 1 AB[1] AB 1 1 after = UF.size[UF.find(A)] after UF.size[UF.find(A)] UF.size UF size UF.find(A) UF.find UF find A last = answer[-1] last answer[-1] answer -1 if before == after:
                answer.append(last)
            else:
                answer.append(last - (after - before) * before)

     before == after before after answer.append(last) answer.append answer append last answer.append(last - (after - before) * before) answer.append answer append last - (after - before) * before last (after - before) * before after - before after before before answer = answer[::-1] answer answer[::-1] answer ::-1 -1 print(*answer[1:], sep="\n") print *answer[1:] answer[1:] answer 1: 1 sep="\n" sep "\n" if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.parent = [i for i in range(n_nodes)]
        self.rank = [1] * n_nodes
        self.size = [1] * n_nodes

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.size[x] += self.size[y]
        else:
            self.parent[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

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

    def get_parent_list(self):
        return [i for i in range(self.n_nodes) if self.find(i) == i]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()} class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.parent = [i for i in range(n_nodes)]
        self.rank = [1] * n_nodes
        self.size = [1] * n_nodes

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.size[x] += self.size[y]
        else:
            self.parent[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

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

    def get_parent_list(self):
        return [i for i in range(self.n_nodes) if self.find(i) == i]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()} UnionFind def input():
    return sys.stdin.readline().strip() def input():
    return sys.stdin.readline().strip() input def main():
    N, M = map(int, input().split())
    Bridge = [list(map(int, input().split())) for _ in range(M)]
    answer = [N * (N - 1) // 2]
    UF = UnionFind(N)
    for i in range(M):
        AB = Bridge[M - i - 1]
        A = AB[0] - 1
        B = AB[1] - 1
        if UF.check(A, B):
            last = answer[-1]
            answer.append(last)
            continue
        else:
            before = UF.size[UF.find(A)]
            UF.unite(AB[0] - 1, AB[1] - 1)
            after = UF.size[UF.find(A)]
            last = answer[-1]
            if before == after:
                answer.append(last)
            else:
                answer.append(last - (after - before) * before)

    answer = answer[::-1]
    print(*answer[1:], sep="\n") def main():
    N, M = map(int, input().split())
    Bridge = [list(map(int, input().split())) for _ in range(M)]
    answer = [N * (N - 1) // 2]
    UF = UnionFind(N)
    for i in range(M):
        AB = Bridge[M - i - 1]
        A = AB[0] - 1
        B = AB[1] - 1
        if UF.check(A, B):
            last = answer[-1]
            answer.append(last)
            continue
        else:
            before = UF.size[UF.find(A)]
            UF.unite(AB[0] - 1, AB[1] - 1)
            after = UF.size[UF.find(A)]
            last = answer[-1]
            if before == after:
                answer.append(last)
            else:
                answer.append(last - (after - before) * before)

    answer = answer[::-1]
    print(*answer[1:], sep="\n") main
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.parent = [i for i in range(n_nodes)]
        self.rank = [1] * n_nodes
        self.size = [1] * n_nodes

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.size[x] += self.size[y]
        else:
            self.parent[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

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

    def get_parent_list(self):
        return [i for i in range(self.n_nodes) if self.find(i) == i]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()}


def main():
    N, M = map(int, input().split())
    Bridge = [list(map(int, input().split())) for _ in range(M)]
    answer = [N * (N - 1) // 2]
    UF = UnionFind(N)
    for i in range(M):
        AB = Bridge[M - i - 1]
        A = AB[0] - 1
        B = AB[1] - 1
        if UF.check(A, B):
            last = answer[-1]
            answer.append(last)
            continue
        else:
            before = UF.size[UF.find(A)]
            UF.unite(AB[0] - 1, AB[1] - 1)
            after = UF.size[UF.find(A)]
            last = answer[-1]
            if before == after:
                answer.append(last)
            else:
                answer.append(last - (after - before) * before)

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


if __name__ == "__main__":
    main()
