class UnionFind():
    def __init__(self, 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)]

N,M = map(int, input().split())
AB = []
for i in range(M):
    AB.append(list(map(int, input().split())))
S = []
uf = UnionFind(N)
for a,b in AB[::-1]:
    if a < b:
        a,b = b,a
    x = uf.size(a-1)
    y = uf.size(b-1)
    uf.union(a-1,b-1)
    z = uf.size(a-1)
    t = z*(z-1)//2 - x*(x-1)//2 - y*(y-1)//2
    if t < 0:
        S.append(0)
    else:
        S.append(t)

ans = 0
for _ in range(M):
    ans += S.pop()
    print(ans) class UnionFind():
    def __init__(self, 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)] UnionFind def __init__(self, n):
        self.parents = [-1]*n
     __init__ 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 N,M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M AB = [] AB [] for i in range(M):
    AB.append(list(map(int, input().split()))) i range(M) range M AB.append(list(map(int, input().split()))) AB.append AB append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split S = [] S [] uf = UnionFind(N) uf UnionFind(N) UnionFind N for a,b in AB[::-1]:
    if a < b:
        a,b = b,a
    x = uf.size(a-1)
    y = uf.size(b-1)
    uf.union(a-1,b-1)
    z = uf.size(a-1)
    t = z*(z-1)//2 - x*(x-1)//2 - y*(y-1)//2
    if t < 0:
        S.append(0)
    else:
        S.append(t) a b AB[::-1] AB ::-1 -1 if a < b:
        a,b = b,a
     a < b a b a,b = b,a a b b a x = uf.size(a-1) x uf.size(a-1) uf.size uf size a-1 a 1 y = uf.size(b-1) y uf.size(b-1) uf.size uf size b-1 b 1 uf.union(a-1,b-1) uf.union uf union a-1 a 1 b-1 b 1 z = uf.size(a-1) z uf.size(a-1) uf.size uf size a-1 a 1 t = z*(z-1)//2 - x*(x-1)//2 - y*(y-1)//2 t z*(z-1)//2 - x*(x-1)//2 - y*(y-1)//2 z*(z-1)//2 - x*(x-1)//2 z*(z-1)//2 z*(z-1) z z-1 z 1 2 x*(x-1)//2 x*(x-1) x x-1 x 1 2 y*(y-1)//2 y*(y-1) y y-1 y 1 2 if t < 0:
        S.append(0)
    else:
        S.append(t) t < 0 t 0 S.append(0) S.append S append 0 S.append(t) S.append S append t ans = 0 ans 0 for _ in range(M):
    ans += S.pop()
    print(ans) _ range(M) range M ans += S.pop() ans S.pop() S.pop S pop print(ans) print ans ans += S.pop() S.pop() ans a,b = b,a b a N,M = map(int, input().split()) map(int, input().split()) N b = b,a a b class UnionFind():
    def __init__(self, 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)] class UnionFind():
    def __init__(self, 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)] UnionFind y = uf.size(b-1) uf.size(b-1) y t = z*(z-1)//2 - x*(x-1)//2 - y*(y-1)//2 z*(z-1)//2 - x*(x-1)//2 - y*(y-1)//2 t x = uf.size(a-1) uf.size(a-1) x ans = 0 0 ans S = [] [] S M = map(int, input().split()) map(int, input().split()) M uf = UnionFind(N) UnionFind(N) uf AB = [] [] AB z = uf.size(a-1) uf.size(a-1) z
class UnionFind():
    def __init__(self, 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)]

N,M = map(int, input().split())
AB = []
for i in range(M):
    AB.append(list(map(int, input().split())))
S = []
uf = UnionFind(N)
for a,b in AB[::-1]:
    if a < b:
        a,b = b,a
    x = uf.size(a-1)
    y = uf.size(b-1)
    uf.union(a-1,b-1)
    z = uf.size(a-1)
    t = z*(z-1)//2 - x*(x-1)//2 - y*(y-1)//2
    if t < 0:
        S.append(0)
    else:
        S.append(t)

ans = 0
for _ in range(M):
    ans += S.pop()
    print(ans)