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

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

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

        if x == y:
            return False
        else:
            if self.v[x] > self.v[y]:
                x, y = y, x
            self.v[x] += self.v[y]
            self.v[y] = x
            return True

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

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


def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())

    es = []
    for _ in range(M):
        a, b = (int(x) - 1 for x in input().split())
        es.append((a, b))
    es.reverse()
    es.pop()

    uf = UnionFind(N)
    ans = [N * (N - 1) // 2]
    t = ans[-1]
    for a, b in es:
        if not uf.same(a, b):
            t -= uf.size(a) * uf.size(b)
        ans.append(t)
        uf.unite(a, b)
    ans.reverse()

    print(*ans, sep='\n')


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

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

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

        if x == y:
            return False
        else:
            if self.v[x] > self.v[y]:
                x, y = y, x
            self.v[x] += self.v[y]
            self.v[y] = x
            return True

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

    def size(self, x):
        return -self.v[self.find(x)] UnionFind def __init__(self, n):
        self.v = [-1] * n

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

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

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

        if x == y:
            return False
        else:
            if self.v[x] > self.v[y]:
                x, y = y, x
            self.v[x] += self.v[y]
            self.v[y] = x
            return True

     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 False
        else:
            if self.v[x] > self.v[y]:
                x, y = y, x
            self.v[x] += self.v[y]
            self.v[y] = x
            return True

     x == y x y return False False if self.v[x] > self.v[y]:
                x, y = y, x
             self.v[x] > self.v[y] self.v[x] self.v self v x self.v[y] self.v self v y x, y = y, x x y y x self.v[x] += self.v[y] self.v[x] self.v self v x self.v[y] self.v self v y self.v[y] = x self.v[y] self.v self v y x return True True self self x x y y 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 size(self, x):
        return -self.v[self.find(x)] size return -self.v[self.find(x)] -self.v[self.find(x)] self.v[self.find(x)] self.v self v self.find(x) self.find self find x self self x x def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())

    es = []
    for _ in range(M):
        a, b = (int(x) - 1 for x in input().split())
        es.append((a, b))
    es.reverse()
    es.pop()

    uf = UnionFind(N)
    ans = [N * (N - 1) // 2]
    t = ans[-1]
    for a, b in es:
        if not uf.same(a, b):
            t -= uf.size(a) * uf.size(b)
        ans.append(t)
        uf.unite(a, b)
    ans.reverse()

    print(*ans, sep='\n') main import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M es = [] es [] for _ in range(M):
        a, b = (int(x) - 1 for x in input().split())
        es.append((a, b))
     _ range(M) range M int(x) - 1 for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) - 1 int(x) int x 1 a, b = (int(x) - 1 for x in input().split()) a (int(x) - 1 for x in input().split()) b es.append((a, b)) es.append es append (a, b) a b es.reverse() es.reverse es reverse es.pop() es.pop es pop uf = UnionFind(N) uf UnionFind(N) UnionFind N ans = [N * (N - 1) // 2] ans [N * (N - 1) // 2] N * (N - 1) // 2 N * (N - 1) N N - 1 N 1 2 t = ans[-1] t ans[-1] ans -1 for a, b in es:
        if not uf.same(a, b):
            t -= uf.size(a) * uf.size(b)
        ans.append(t)
        uf.unite(a, b)
     a b es if not uf.same(a, b):
            t -= uf.size(a) * uf.size(b)
         not uf.same(a, b) uf.same(a, b) uf.same uf same a b t -= uf.size(a) * uf.size(b) t uf.size(a) * uf.size(b) uf.size(a) uf.size uf size a uf.size(b) uf.size uf size b ans.append(t) ans.append ans append t uf.unite(a, b) uf.unite uf unite a b ans.reverse() ans.reverse ans reverse print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main class UnionFind:
    def __init__(self, n):
        self.v = [-1] * n

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

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

        if x == y:
            return False
        else:
            if self.v[x] > self.v[y]:
                x, y = y, x
            self.v[x] += self.v[y]
            self.v[y] = x
            return True

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

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

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

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

        if x == y:
            return False
        else:
            if self.v[x] > self.v[y]:
                x, y = y, x
            self.v[x] += self.v[y]
            self.v[y] = x
            return True

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

    def size(self, x):
        return -self.v[self.find(x)] UnionFind def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())

    es = []
    for _ in range(M):
        a, b = (int(x) - 1 for x in input().split())
        es.append((a, b))
    es.reverse()
    es.pop()

    uf = UnionFind(N)
    ans = [N * (N - 1) // 2]
    t = ans[-1]
    for a, b in es:
        if not uf.same(a, b):
            t -= uf.size(a) * uf.size(b)
        ans.append(t)
        uf.unite(a, b)
    ans.reverse()

    print(*ans, sep='\n') def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())

    es = []
    for _ in range(M):
        a, b = (int(x) - 1 for x in input().split())
        es.append((a, b))
    es.reverse()
    es.pop()

    uf = UnionFind(N)
    ans = [N * (N - 1) // 2]
    t = ans[-1]
    for a, b in es:
        if not uf.same(a, b):
            t -= uf.size(a) * uf.size(b)
        ans.append(t)
        uf.unite(a, b)
    ans.reverse()

    print(*ans, sep='\n') main
class UnionFind:
    def __init__(self, n):
        self.v = [-1] * n

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

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

        if x == y:
            return False
        else:
            if self.v[x] > self.v[y]:
                x, y = y, x
            self.v[x] += self.v[y]
            self.v[y] = x
            return True

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

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


def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())

    es = []
    for _ in range(M):
        a, b = (int(x) - 1 for x in input().split())
        es.append((a, b))
    es.reverse()
    es.pop()

    uf = UnionFind(N)
    ans = [N * (N - 1) // 2]
    t = ans[-1]
    for a, b in es:
        if not uf.same(a, b):
            t -= uf.size(a) * uf.size(b)
        ans.append(t)
        uf.unite(a, b)
    ans.reverse()

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()
