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

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1


N, M = list(map(int, input().split()))
L = [None]*M
for j in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    L[j] = (a, b)
L = L[::-1]

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

for j in range(M):
    a, b = L[j]
    if uf.find(a) == uf.find(b):
        ans[j+1] = ans[j]
    else:
        va = uf.size(a)
        vb = uf.size(b)
        ans[j+1] = ans[j]-va*vb
    uf.union(a, b)
# print(ans)
ans = ans[::-1]
for j in range(1, M+1):
    print(ans[j]) class UnionFind():
    def __init__(self, n):
        self.parents = [-1]*n
        self.rank = [0]*n

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1 UnionFind def __init__(self, n):
        self.parents = [-1]*n
        self.rank = [0]*n

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

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

     self.parents[x] < 0 self.parents[x] self.parents self parents x 0 return x x return self.find(self.parents[x]) self.find(self.parents[x]) self.find self find self.parents[x] self.parents self parents x self self x x 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 union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1 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.rank[x] < self.rank[y]:
            x, y = y, x
         self.rank[x] < self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank 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 if self.rank[x] == self.rank[y]:
            self.rank[x] += 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[x] += 1 self.rank[x] self.rank self rank x 1 self self x x y y N, M = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M L = [None]*M L [None]*M [None] None M for j in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    L[j] = (a, b) j range(M) range M a, b = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split b a -= 1 a 1 b -= 1 b 1 L[j] = (a, b) L[j] L j (a, b) a b L = L[::-1] L L[::-1] L ::-1 -1 ans = [0]*(M+1) ans [0]*(M+1) [0] 0 M+1 M 1 ans[0] = (N*(N-1))//2 ans[0] ans 0 (N*(N-1))//2 N*(N-1) N N-1 N 1 2 uf = UnionFind(N) uf UnionFind(N) UnionFind N for j in range(M):
    a, b = L[j]
    if uf.find(a) == uf.find(b):
        ans[j+1] = ans[j]
    else:
        va = uf.size(a)
        vb = uf.size(b)
        ans[j+1] = ans[j]-va*vb
    uf.union(a, b)
# print(ans) j range(M) range M a, b = L[j] a L[j] L j b if uf.find(a) == uf.find(b):
        ans[j+1] = ans[j]
    else:
        va = uf.size(a)
        vb = uf.size(b)
        ans[j+1] = ans[j]-va*vb
     uf.find(a) == uf.find(b) uf.find(a) uf.find uf find a uf.find(b) uf.find uf find b ans[j+1] = ans[j] ans[j+1] ans j+1 j 1 ans[j] ans j va = uf.size(a) va uf.size(a) uf.size uf size a vb = uf.size(b) vb uf.size(b) uf.size uf size b ans[j+1] = ans[j]-va*vb ans[j+1] ans j+1 j 1 ans[j]-va*vb ans[j] ans j va*vb va vb uf.union(a, b) uf.union uf union a b ans = ans[::-1] ans ans[::-1] ans ::-1 -1 for j in range(1, M+1):
    print(ans[j]) j range(1, M+1) range 1 M+1 M 1 print(ans[j]) print ans[j] ans j L = [None]*M [None]*M L N, M = list(map(int, input().split())) list(map(int, input().split())) N a, b = list(map(int, input().split())) list(map(int, input().split())) a b = L[j] L[j] b b = list(map(int, input().split())) list(map(int, input().split())) b a, b = L[j] L[j] a uf = UnionFind(N) UnionFind(N) uf b -= 1 1 b va = uf.size(a) uf.size(a) va ans = [0]*(M+1) [0]*(M+1) ans vb = uf.size(b) uf.size(b) vb M = list(map(int, input().split())) list(map(int, input().split())) M a -= 1 1 a ans = ans[::-1] ans[::-1] ans class UnionFind():
    def __init__(self, n):
        self.parents = [-1]*n
        self.rank = [0]*n

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1 class UnionFind():
    def __init__(self, n):
        self.parents = [-1]*n
        self.rank = [0]*n

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1 UnionFind L = L[::-1] L[::-1] L
class UnionFind():
    def __init__(self, n):
        self.parents = [-1]*n
        self.rank = [0]*n

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1


N, M = list(map(int, input().split()))
L = [None]*M
for j in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    L[j] = (a, b)
L = L[::-1]

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

for j in range(M):
    a, b = L[j]
    if uf.find(a) == uf.find(b):
        ans[j+1] = ans[j]
    else:
        va = uf.size(a)
        vb = uf.size(b)
        ans[j+1] = ans[j]-va*vb
    uf.union(a, b)
# print(ans)
ans = ans[::-1]
for j in range(1, M+1):
    print(ans[j])
