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)

   

    
N, M = map(int,input().split())
bridge = []
for i in range(M):
    A, B = map(int,input().split())
    bridge.append((A - 1, B - 1))
    
uf = UnionFind(N)
ans = [N * (N - 1) // 2]
cnt = 0
for i in range(M - 1):
    A, B = bridge[-i-1]
    if not uf.same(A, B):
        cnt += uf.size(A) * uf.size(B)
        uf.union(A, B)
    ans.append(ans[0] - cnt)
for i in range(M):
    print(ans[-i-1]) 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 N, M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M bridge = [] bridge [] for i in range(M):
    A, B = map(int,input().split())
    bridge.append((A - 1, B - 1))
     i range(M) range M A, B = map(int,input().split()) A map(int,input().split()) map int input().split() ().split () input split B bridge.append((A - 1, B - 1)) bridge.append bridge append (A - 1, B - 1) A - 1 A 1 B - 1 B 1 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 cnt = 0 cnt 0 for i in range(M - 1):
    A, B = bridge[-i-1]
    if not uf.same(A, B):
        cnt += uf.size(A) * uf.size(B)
        uf.union(A, B)
    ans.append(ans[0] - cnt) i range(M - 1) range M - 1 M 1 A, B = bridge[-i-1] A bridge[-i-1] bridge -i-1 -i i 1 B if not uf.same(A, B):
        cnt += uf.size(A) * uf.size(B)
        uf.union(A, B)
     not uf.same(A, B) uf.same(A, B) uf.same uf same A B cnt += uf.size(A) * uf.size(B) cnt 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.append(ans[0] - cnt) ans.append ans append ans[0] - cnt ans[0] ans 0 cnt for i in range(M):
    print(ans[-i-1]) i range(M) range M print(ans[-i-1]) print ans[-i-1] ans -i-1 -i i 1 uf = UnionFind(N) UnionFind(N) uf 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 B = bridge[-i-1] bridge[-i-1] B A, B = map(int,input().split()) map(int,input().split()) A ans = [N * (N - 1) // 2] [N * (N - 1) // 2] ans cnt = 0 0 cnt cnt += uf.size(A) * uf.size(B) uf.size(A) * uf.size(B) cnt B = map(int,input().split()) map(int,input().split()) B N, M = map(int,input().split()) map(int,input().split()) N A, B = bridge[-i-1] bridge[-i-1] A M = map(int,input().split()) map(int,input().split()) M bridge = [] [] bridge
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)

   

    
N, M = map(int,input().split())
bridge = []
for i in range(M):
    A, B = map(int,input().split())
    bridge.append((A - 1, B - 1))
    
uf = UnionFind(N)
ans = [N * (N - 1) // 2]
cnt = 0
for i in range(M - 1):
    A, B = bridge[-i-1]
    if not uf.same(A, B):
        cnt += uf.size(A) * uf.size(B)
        uf.union(A, B)
    ans.append(ans[0] - cnt)
for i in range(M):
    print(ans[-i-1])