N,M=map(int,input().split())
D=[list(map(int, input().split())) for _ in range(M)]
C=D[::-1]
par=[i for i in range(N)]
rank=[0]*(N)
size=[1]*N

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]

def same(x,y):
  return find(x)==find(y)

def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1

A=[]
d=0
for a,b in C:
  a-=1
  b-=1
  x=find(a)
  y=find(b)
  if x!=y:
    d+=size[x]*size[y]
  union(a,b)
  A.append(d) 
A=A[::-1]
A.append(0)
a=N*(N-1)//2
for i in range(1,M+1):
  print(a-A[i]) N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M list(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split D=[list(map(int, input().split())) for _ in range(M)] D [list(map(int, input().split())) for _ in range(M)] C=D[::-1] C D[::-1] D ::-1 -1 i for i in range(N) for i in range(N) i range(N) range N for i in range(N) i par=[i for i in range(N)] par [i for i in range(N)] rank=[0]*(N) rank [0]*(N) [0] 0 N size=[1]*N size [1]*N [1] 1 N 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 same(x,y):
  return find(x)==find(y) same return find(x)==find(y) find(x)==find(y) find(x) find x find(y) find y x x y y def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1 union x=find(x) x find(x) find x y=find(y) y find(y) find y if x==y:
    return 
   x==y x y return if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1 rank[x]>rank[y] rank[x] rank x rank[y] rank y par[y]=x par[y] par y x size[x]+=size[y] size[x] size x size[y] size y par[x]=y par[x] par x y size[y]+=size[x] size[y] size y size[x] size x if rank[x]==rank[y]:
      rank[y]+=1 rank[x]==rank[y] rank[x] rank x rank[y] rank y rank[y]+=1 rank[y] rank y 1 x x y y A=[] A [] d=0 d 0 for a,b in C:
  a-=1
  b-=1
  x=find(a)
  y=find(b)
  if x!=y:
    d+=size[x]*size[y]
  union(a,b)
  A.append(d)  a b C a-=1 a 1 b-=1 b 1 x=find(a) x find(a) find a y=find(b) y find(b) find b if x!=y:
    d+=size[x]*size[y]
   x!=y x y d+=size[x]*size[y] d size[x]*size[y] size[x] size x size[y] size y union(a,b) union a b A.append(d) A.append A append d A=A[::-1] A A[::-1] A ::-1 -1 A.append(0) A.append A append 0 a=N*(N-1)//2 a N*(N-1)//2 N*(N-1) N N-1 N 1 2 for i in range(1,M+1):
  print(a-A[i]) i range(1,M+1) range 1 M+1 M 1 print(a-A[i]) print a-A[i] a A[i] A i y=find(b) find(b) y 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 d+=size[x]*size[y] size[x]*size[y] d M=map(int,input().split()) map(int,input().split()) M A=[] [] A D=[list(map(int, input().split())) for _ in range(M)] [list(map(int, input().split())) for _ in range(M)] D A=A[::-1] A[::-1] A b-=1 1 b par=[i for i in range(N)] [i for i in range(N)] par rank=[0]*(N) [0]*(N) rank def same(x,y):
  return find(x)==find(y) def same(x,y):
  return find(x)==find(y) same x=find(a) find(a) x d=0 0 d a=N*(N-1)//2 N*(N-1)//2 a N,M=map(int,input().split()) map(int,input().split()) N C=D[::-1] D[::-1] C def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1 def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1 union a-=1 1 a size=[1]*N [1]*N size
N,M=map(int,input().split())
D=[list(map(int, input().split())) for _ in range(M)]
C=D[::-1]
par=[i for i in range(N)]
rank=[0]*(N)
size=[1]*N

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]

def same(x,y):
  return find(x)==find(y)

def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1

A=[]
d=0
for a,b in C:
  a-=1
  b-=1
  x=find(a)
  y=find(b)
  if x!=y:
    d+=size[x]*size[y]
  union(a,b)
  A.append(d) 
A=A[::-1]
A.append(0)
a=N*(N-1)//2
for i in range(1,M+1):
  print(a-A[i])