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

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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


def main():
    N, M = map(int, input().split())
    bridge = [list(map(int, input().split())) for _ in range(M)]

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

    for i in range(-1, -1 * M, -1):
        a = bridge[i][0] - 1
        b = bridge[i][1] - 1
        if not uf.same(a, b):
            ans[i-1] = ans[i] - uf.size(a) * uf.size(b)
            uf.union(a, b)
        else:
            ans[i-1] = ans[i]

    for a in ans:
        print(a)


if __name__ == "__main__":
    main() class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

    def same(self, x, y):
        return self.find(x) == self.find(y) UnionFind def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

     __init__ self.n = n self.n self n n self.parents = [-1] * n self.parents self parents [-1] * n [-1] -1 n self self n n def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

     find if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

     self.parents[x] < 0 self.parents[x] self.parents self parents x 0 return x x self.parents[x] = self.find(self.parents[x]) self.parents[x] self.parents self parents x self.find(self.parents[x]) self.find self find self.parents[x] self.parents self parents x return self.parents[x] self.parents[x] self.parents self parents x self self x x def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

     union 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.parents[x] > self.parents[y]:
            x, y = y, x

         self.parents[x] > self.parents[y] self.parents[x] self.parents self parents x self.parents[y] self.parents self parents y x, y = y, x x y y x self.parents[x] += self.parents[y] self.parents[x] self.parents self parents x self.parents[y] self.parents self parents y self.parents[y] = x self.parents[y] self.parents self parents y x self self x x y y def size(self, x):
        return -self.parents[self.find(x)]

     size return -self.parents[self.find(x)] -self.parents[self.find(x)] self.parents[self.find(x)] self.parents self parents self.find(x) self.find self find x self self x x def same(self, x, y):
        return self.find(x) == self.find(y) same 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 main():
    N, M = map(int, input().split())
    bridge = [list(map(int, input().split())) for _ in range(M)]

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

    for i in range(-1, -1 * M, -1):
        a = bridge[i][0] - 1
        b = bridge[i][1] - 1
        if not uf.same(a, b):
            ans[i-1] = ans[i] - uf.size(a) * uf.size(b)
            uf.union(a, b)
        else:
            ans[i-1] = ans[i]

    for a in ans:
        print(a) 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)] uf = UnionFind(N) uf UnionFind(N) UnionFind N ans = [N*(N-1)//2]*M ans [N*(N-1)//2]*M [N*(N-1)//2] N*(N-1)//2 N*(N-1) N N-1 N 1 2 M for i in range(-1, -1 * M, -1):
        a = bridge[i][0] - 1
        b = bridge[i][1] - 1
        if not uf.same(a, b):
            ans[i-1] = ans[i] - uf.size(a) * uf.size(b)
            uf.union(a, b)
        else:
            ans[i-1] = ans[i]

     i range(-1, -1 * M, -1) range -1 -1 * M -1 M -1 a = bridge[i][0] - 1 a bridge[i][0] - 1 bridge[i][0] [i] bridge i 0 1 b = bridge[i][1] - 1 b bridge[i][1] - 1 bridge[i][1] [i] bridge i 1 1 if not uf.same(a, b):
            ans[i-1] = ans[i] - uf.size(a) * uf.size(b)
            uf.union(a, b)
        else:
            ans[i-1] = ans[i]

     not uf.same(a, b) uf.same(a, b) uf.same uf same a b ans[i-1] = ans[i] - uf.size(a) * uf.size(b) ans[i-1] ans i-1 i 1 ans[i] - uf.size(a) * uf.size(b) ans[i] ans i uf.size(a) * uf.size(b) uf.size(a) uf.size uf size a uf.size(b) uf.size uf size b uf.union(a, b) uf.union uf union a b ans[i-1] = ans[i] ans[i-1] ans i-1 i 1 ans[i] ans i for a in ans:
        print(a) a ans print(a) print a if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

    def same(self, x, y):
        return self.find(x) == self.find(y) class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

    def same(self, x, y):
        return self.find(x) == self.find(y) UnionFind def main():
    N, M = map(int, input().split())
    bridge = [list(map(int, input().split())) for _ in range(M)]

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

    for i in range(-1, -1 * M, -1):
        a = bridge[i][0] - 1
        b = bridge[i][1] - 1
        if not uf.same(a, b):
            ans[i-1] = ans[i] - uf.size(a) * uf.size(b)
            uf.union(a, b)
        else:
            ans[i-1] = ans[i]

    for a in ans:
        print(a) def main():
    N, M = map(int, input().split())
    bridge = [list(map(int, input().split())) for _ in range(M)]

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

    for i in range(-1, -1 * M, -1):
        a = bridge[i][0] - 1
        b = bridge[i][1] - 1
        if not uf.same(a, b):
            ans[i-1] = ans[i] - uf.size(a) * uf.size(b)
            uf.union(a, b)
        else:
            ans[i-1] = ans[i]

    for a in ans:
        print(a) main
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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


def main():
    N, M = map(int, input().split())
    bridge = [list(map(int, input().split())) for _ in range(M)]

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

    for i in range(-1, -1 * M, -1):
        a = bridge[i][0] - 1
        b = bridge[i][1] - 1
        if not uf.same(a, b):
            ans[i-1] = ans[i] - uf.size(a) * uf.size(b)
            uf.union(a, b)
        else:
            ans[i-1] = ans[i]

    for a in ans:
        print(a)


if __name__ == "__main__":
    main()
