maxn = 100000

n , m = map(int, input().split())

par = [0] * n
rank = [0] * n
siz = [1] * n

#初期化
for i in range(n):
    par[i] = i
    rank[i] = 0

#判定(一番上野根を求める)
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
#結合
def unite(x , y):
    rx = find(x)
    ry = find(y)
    
    if rx == ry:
        return
    
    if rank[rx] < rank[ry]:
        par[rx] = ry
        siz[ry] += siz[rx]
        siz[rx] = 0
    elif rank[rx] > rank[ry]:
        par[ry] = rx
        siz[rx] += siz[ry]
        siz[ry] = 0
    else:
        par[ry] = x
        siz[rx] += siz[ry]
        siz[ry] = 0
        rank[rx] += 1

a = [0] * m
b = [0] * m
for i in range(m):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    
nn = [0]*(maxn+1)
for i in range(maxn+1):
    nn[i] = i * (i-1) // 2
    
dis = [0]*m
ans = n*(n-1) // 2
dis[m-1] = ans
for i in range(m-1,0,-1):
    if find(a[i]) == find(b[i]):
        dis[i-1] = ans
    else:
        ans -= (siz[find(a[i])] * siz[find(b[i])])
        dis[i-1] = ans
        
    unite(a[i],b[i])
    
for i in range(m):
    print(dis[i]) maxn = 100000 maxn 100000 n , m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m par = [0] * n par [0] * n [0] 0 n rank = [0] * n rank [0] * n [0] 0 n siz = [1] * n siz [1] * n [1] 1 n for i in range(n):
    par[i] = i
    rank[i] = 0

#判定(一番上野根を求める) i range(n) range n par[i] = i par[i] par i i rank[i] = 0 rank[i] rank i 0 def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
#結合 find if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
#結合 par[x] == x par[x] par x x return x x par[x] = find(par[x]) par[x] par x find(par[x]) find par[x] par x return par[x] par[x] par x x x def unite(x , y):
    rx = find(x)
    ry = find(y)
    
    if rx == ry:
        return
    
    if rank[rx] < rank[ry]:
        par[rx] = ry
        siz[ry] += siz[rx]
        siz[rx] = 0
    elif rank[rx] > rank[ry]:
        par[ry] = rx
        siz[rx] += siz[ry]
        siz[ry] = 0
    else:
        par[ry] = x
        siz[rx] += siz[ry]
        siz[ry] = 0
        rank[rx] += 1 unite rx = find(x) rx find(x) find x ry = find(y) ry find(y) find y if rx == ry:
        return
    
     rx == ry rx ry return if rank[rx] < rank[ry]:
        par[rx] = ry
        siz[ry] += siz[rx]
        siz[rx] = 0
    elif rank[rx] > rank[ry]:
        par[ry] = rx
        siz[rx] += siz[ry]
        siz[ry] = 0
    else:
        par[ry] = x
        siz[rx] += siz[ry]
        siz[ry] = 0
        rank[rx] += 1 rank[rx] < rank[ry] rank[rx] rank rx rank[ry] rank ry par[rx] = ry par[rx] par rx ry siz[ry] += siz[rx] siz[ry] siz ry siz[rx] siz rx siz[rx] = 0 siz[rx] siz rx 0 elif rank[rx] > rank[ry]:
        par[ry] = rx
        siz[rx] += siz[ry]
        siz[ry] = 0
     rank[rx] > rank[ry] rank[rx] rank rx rank[ry] rank ry par[ry] = rx par[ry] par ry rx siz[rx] += siz[ry] siz[rx] siz rx siz[ry] siz ry siz[ry] = 0 siz[ry] siz ry 0 par[ry] = x par[ry] par ry x siz[rx] += siz[ry] siz[rx] siz rx siz[ry] siz ry siz[ry] = 0 siz[ry] siz ry 0 rank[rx] += 1 rank[rx] rank rx 1 x x y y a = [0] * m a [0] * m [0] 0 m b = [0] * m b [0] * m [0] 0 m for i in range(m):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
     i range(m) range m a[i],b[i] = map(int,input().split()) a[i] a i map(int,input().split()) map int input().split() ().split () input split b[i] b i a[i] -= 1 a[i] a i 1 b[i] -= 1 b[i] b i 1 nn = [0]*(maxn+1) nn [0]*(maxn+1) [0] 0 maxn+1 maxn 1 for i in range(maxn+1):
    nn[i] = i * (i-1) // 2
     i range(maxn+1) range maxn+1 maxn 1 nn[i] = i * (i-1) // 2 nn[i] nn i i * (i-1) // 2 i * (i-1) i i-1 i 1 2 dis = [0]*m dis [0]*m [0] 0 m ans = n*(n-1) // 2 ans n*(n-1) // 2 n*(n-1) n n-1 n 1 2 dis[m-1] = ans dis[m-1] dis m-1 m 1 ans for i in range(m-1,0,-1):
    if find(a[i]) == find(b[i]):
        dis[i-1] = ans
    else:
        ans -= (siz[find(a[i])] * siz[find(b[i])])
        dis[i-1] = ans
        
    unite(a[i],b[i])
     i range(m-1,0,-1) range m-1 m 1 0 -1 if find(a[i]) == find(b[i]):
        dis[i-1] = ans
    else:
        ans -= (siz[find(a[i])] * siz[find(b[i])])
        dis[i-1] = ans
        
     find(a[i]) == find(b[i]) find(a[i]) find a[i] a i find(b[i]) find b[i] b i dis[i-1] = ans dis[i-1] dis i-1 i 1 ans ans -= (siz[find(a[i])] * siz[find(b[i])]) ans siz[find(a[i])] * siz[find(b[i])] siz[find(a[i])] siz find(a[i]) find a[i] a i siz[find(b[i])] siz find(b[i]) find b[i] b i dis[i-1] = ans dis[i-1] dis i-1 i 1 ans unite(a[i],b[i]) unite a[i] a i b[i] b i for i in range(m):
    print(dis[i]) i range(m) range m print(dis[i]) print dis[i] dis i m = map(int, input().split()) map(int, input().split()) m dis = [0]*m [0]*m dis par = [0] * n [0] * n par n , m = map(int, input().split()) map(int, input().split()) n a = [0] * m [0] * m a nn = [0]*(maxn+1) [0]*(maxn+1) nn maxn = 100000 100000 maxn def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
#結合 def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
#結合 find b = [0] * m [0] * m b def unite(x , y):
    rx = find(x)
    ry = find(y)
    
    if rx == ry:
        return
    
    if rank[rx] < rank[ry]:
        par[rx] = ry
        siz[ry] += siz[rx]
        siz[rx] = 0
    elif rank[rx] > rank[ry]:
        par[ry] = rx
        siz[rx] += siz[ry]
        siz[ry] = 0
    else:
        par[ry] = x
        siz[rx] += siz[ry]
        siz[ry] = 0
        rank[rx] += 1 def unite(x , y):
    rx = find(x)
    ry = find(y)
    
    if rx == ry:
        return
    
    if rank[rx] < rank[ry]:
        par[rx] = ry
        siz[ry] += siz[rx]
        siz[rx] = 0
    elif rank[rx] > rank[ry]:
        par[ry] = rx
        siz[rx] += siz[ry]
        siz[ry] = 0
    else:
        par[ry] = x
        siz[rx] += siz[ry]
        siz[ry] = 0
        rank[rx] += 1 unite ans = n*(n-1) // 2 n*(n-1) // 2 ans ans -= (siz[find(a[i])] * siz[find(b[i])]) siz[find(a[i])] * siz[find(b[i])] ans siz = [1] * n [1] * n siz rank = [0] * n [0] * n rank
maxn = 100000

n , m = map(int, input().split())

par = [0] * n
rank = [0] * n
siz = [1] * n

#初期化
for i in range(n):
    par[i] = i
    rank[i] = 0

#判定(一番上野根を求める)
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
#結合
def unite(x , y):
    rx = find(x)
    ry = find(y)
    
    if rx == ry:
        return
    
    if rank[rx] < rank[ry]:
        par[rx] = ry
        siz[ry] += siz[rx]
        siz[rx] = 0
    elif rank[rx] > rank[ry]:
        par[ry] = rx
        siz[rx] += siz[ry]
        siz[ry] = 0
    else:
        par[ry] = x
        siz[rx] += siz[ry]
        siz[ry] = 0
        rank[rx] += 1

a = [0] * m
b = [0] * m
for i in range(m):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    
nn = [0]*(maxn+1)
for i in range(maxn+1):
    nn[i] = i * (i-1) // 2
    
dis = [0]*m
ans = n*(n-1) // 2
dis[m-1] = ans
for i in range(m-1,0,-1):
    if find(a[i]) == find(b[i]):
        dis[i-1] = ans
    else:
        ans -= (siz[find(a[i])] * siz[find(b[i])])
        dis[i-1] = ans
        
    unite(a[i],b[i])
    
for i in range(m):
    print(dis[i])