N,M=list(map(int,input().split()))
def f(n):
   return n*(n-1)//2
ans=f(N)
root=[i for i in range(N+1)]
height=[1]*(N+1)
def find(a):
   f=a
   if a==root[a]:
      return a
   while a!=root[a]:
      a=root[a]
   root[f]=a
   return a
def union(a,b):
   A=find(a)
   B=find(b)
   global ans
   if A==B:
      return
   ans+=f(height[A])+f(height[B])
   if height[A]>height[B]:
      root[B]=root[A]
      height[A]+=height[B]
      height[B]=0
   else:
      root[A]=root[B]
      height[B]+=height[A]
      height[A]=0
   ans-=f(max(height[A],height[B]))
l=[tuple(map(int,input().split())) for i in range(M)]
l=l[::-1]
ans_m=[ans]
for i in range(M):
   a,b=l[i]
   union(a,b)
   ans_m.append(ans)
ans_m=ans_m[::-1]
for i in range(1,M+1):
   print(ans_m[i]) 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 def f(n):
   return n*(n-1)//2 f return n*(n-1)//2 n*(n-1)//2 n*(n-1) n n-1 n 1 2 n n ans=f(N) ans f(N) f N i for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) i root=[i for i in range(N+1)] root [i for i in range(N+1)] height=[1]*(N+1) height [1]*(N+1) [1] 1 N+1 N 1 def find(a):
   f=a
   if a==root[a]:
      return a
   while a!=root[a]:
      a=root[a]
   root[f]=a
   return a find f=a f a if a==root[a]:
      return a
    a==root[a] a root[a] root a return a a while a!=root[a]:
      a=root[a]
    a!=root[a] a root[a] root a a=root[a] a root[a] root a root[f]=a root[f] root f a return a a a a def union(a,b):
   A=find(a)
   B=find(b)
   global ans
   if A==B:
      return
   ans+=f(height[A])+f(height[B])
   if height[A]>height[B]:
      root[B]=root[A]
      height[A]+=height[B]
      height[B]=0
   else:
      root[A]=root[B]
      height[B]+=height[A]
      height[A]=0
   ans-=f(max(height[A],height[B])) union A=find(a) A find(a) find a B=find(b) B find(b) find b global ans if A==B:
      return
    A==B A B return ans+=f(height[A])+f(height[B]) ans f(height[A])+f(height[B]) f(height[A]) f height[A] height A f(height[B]) f height[B] height B if height[A]>height[B]:
      root[B]=root[A]
      height[A]+=height[B]
      height[B]=0
   else:
      root[A]=root[B]
      height[B]+=height[A]
      height[A]=0
    height[A]>height[B] height[A] height A height[B] height B root[B]=root[A] root[B] root B root[A] root A height[A]+=height[B] height[A] height A height[B] height B height[B]=0 height[B] height B 0 root[A]=root[B] root[A] root A root[B] root B height[B]+=height[A] height[B] height B height[A] height A height[A]=0 height[A] height A 0 ans-=f(max(height[A],height[B])) ans f(max(height[A],height[B])) f max(height[A],height[B]) max height[A] height A height[B] height B a a b b tuple(map(int,input().split())) for i in range(M) for i in range(M) i range(M) range M for i in range(M) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split l=[tuple(map(int,input().split())) for i in range(M)] l [tuple(map(int,input().split())) for i in range(M)] l=l[::-1] l l[::-1] l ::-1 -1 ans_m=[ans] ans_m [ans] ans for i in range(M):
   a,b=l[i]
   union(a,b)
   ans_m.append(ans) i range(M) range M a,b=l[i] a l[i] l i b union(a,b) union a b ans_m.append(ans) ans_m.append ans_m append ans ans_m=ans_m[::-1] ans_m ans_m[::-1] ans_m ::-1 -1 for i in range(1,M+1):
   print(ans_m[i]) i range(1,M+1) range 1 M+1 M 1 print(ans_m[i]) print ans_m[i] ans_m i a,b=l[i] l[i] a ans=f(N) f(N) ans def f(n):
   return n*(n-1)//2 def f(n):
   return n*(n-1)//2 f N,M=list(map(int,input().split())) list(map(int,input().split())) N def find(a):
   f=a
   if a==root[a]:
      return a
   while a!=root[a]:
      a=root[a]
   root[f]=a
   return a def find(a):
   f=a
   if a==root[a]:
      return a
   while a!=root[a]:
      a=root[a]
   root[f]=a
   return a find l=l[::-1] l[::-1] l def union(a,b):
   A=find(a)
   B=find(b)
   global ans
   if A==B:
      return
   ans+=f(height[A])+f(height[B])
   if height[A]>height[B]:
      root[B]=root[A]
      height[A]+=height[B]
      height[B]=0
   else:
      root[A]=root[B]
      height[B]+=height[A]
      height[A]=0
   ans-=f(max(height[A],height[B])) def union(a,b):
   A=find(a)
   B=find(b)
   global ans
   if A==B:
      return
   ans+=f(height[A])+f(height[B])
   if height[A]>height[B]:
      root[B]=root[A]
      height[A]+=height[B]
      height[B]=0
   else:
      root[A]=root[B]
      height[B]+=height[A]
      height[A]=0
   ans-=f(max(height[A],height[B])) union height=[1]*(N+1) [1]*(N+1) height M=list(map(int,input().split())) list(map(int,input().split())) M l=[tuple(map(int,input().split())) for i in range(M)] [tuple(map(int,input().split())) for i in range(M)] l root=[i for i in range(N+1)] [i for i in range(N+1)] root ans_m=ans_m[::-1] ans_m[::-1] ans_m ans_m=[ans] [ans] ans_m b=l[i] l[i] b
N,M=list(map(int,input().split()))
def f(n):
   return n*(n-1)//2
ans=f(N)
root=[i for i in range(N+1)]
height=[1]*(N+1)
def find(a):
   f=a
   if a==root[a]:
      return a
   while a!=root[a]:
      a=root[a]
   root[f]=a
   return a
def union(a,b):
   A=find(a)
   B=find(b)
   global ans
   if A==B:
      return
   ans+=f(height[A])+f(height[B])
   if height[A]>height[B]:
      root[B]=root[A]
      height[A]+=height[B]
      height[B]=0
   else:
      root[A]=root[B]
      height[B]+=height[A]
      height[A]=0
   ans-=f(max(height[A],height[B]))
l=[tuple(map(int,input().split())) for i in range(M)]
l=l[::-1]
ans_m=[ans]
for i in range(M):
   a,b=l[i]
   union(a,b)
   ans_m.append(ans)
ans_m=ans_m[::-1]
for i in range(1,M+1):
   print(ans_m[i])