import sys
input = sys.stdin.buffer.readline

n, m = map(int, input().split())
X = []
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    X.append((a, b))

X.reverse()

def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x]

def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

def Same(x, y, par):
    return Find(x, par) == Find(y, par)

def Size(x, par):
    return -par[Find(x, par)]

temp = n*(n-1)//2
ans = [0]*m

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

for i in range(m):
    a, b = X[i]
    ans[i] = temp
    if Same(a, b, par):
        continue
    else:
        pre_a = Size(a, par)
        pre_b = Size(b, par)
        Unite(a, b, par, rank)
        temp -= pre_a*pre_b
        #if temp <= 0:
        #temp = 0

ans.reverse()
#print(ans)
for i in range(len(ans)):
    print(ans[i]) import sys sys input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m X = [] X [] for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    X.append((a, b)) i range(m) range m a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b a, b = a-1, b-1 a a-1 a 1 b b-1 b 1 X.append((a, b)) X.append X append (a, b) a b X.reverse() X.reverse X reverse def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x] Find if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x] par[x] < 0 par[x] par x 0 return x x par[x] = Find(par[x], par) par[x] par x Find(par[x], par) Find par[x] par x par return par[x] par[x] par x x x par par def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1 Unite x = Find(x, par) x Find(x, par) Find x par y = Find(y, par) y Find(y, par) Find y par if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1 x != y x y if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1 rank[x] < rank[y] rank[x] rank x rank[y] rank y par[y] += par[x] par[y] par y par[x] par x par[x] = y par[x] par x y par[x] += par[y] par[x] par x par[y] par y par[y] = x par[y] par y x if rank[x] == rank[y]:
                rank[x] += 1 rank[x] == rank[y] rank[x] rank x rank[y] rank y rank[x] += 1 rank[x] rank x 1 x x y y par par rank rank def Same(x, y, par):
    return Find(x, par) == Find(y, par) Same return Find(x, par) == Find(y, par) Find(x, par) == Find(y, par) Find(x, par) Find x par Find(y, par) Find y par x x y y par par def Size(x, par):
    return -par[Find(x, par)] Size return -par[Find(x, par)] -par[Find(x, par)] par[Find(x, par)] par Find(x, par) Find x par x x par par temp = n*(n-1)//2 temp n*(n-1)//2 n*(n-1) n n-1 n 1 2 ans = [0]*m ans [0]*m [0] 0 m par = [-1]* n par [-1]* n [-1] -1 n rank = [0]*n rank [0]*n [0] 0 n for i in range(m):
    a, b = X[i]
    ans[i] = temp
    if Same(a, b, par):
        continue
    else:
        pre_a = Size(a, par)
        pre_b = Size(b, par)
        Unite(a, b, par, rank)
        temp -= pre_a*pre_b
        #if temp <= 0:
        #temp = 0 i range(m) range m a, b = X[i] a X[i] X i b ans[i] = temp ans[i] ans i temp if Same(a, b, par):
        continue
    else:
        pre_a = Size(a, par)
        pre_b = Size(b, par)
        Unite(a, b, par, rank)
        temp -= pre_a*pre_b
        #if temp <= 0:
        #temp = 0 Same(a, b, par) Same a b par continue pre_a = Size(a, par) pre_a Size(a, par) Size a par pre_b = Size(b, par) pre_b Size(b, par) Size b par Unite(a, b, par, rank) Unite a b par rank temp -= pre_a*pre_b temp pre_a*pre_b pre_a pre_b ans.reverse() ans.reverse ans reverse for i in range(len(ans)):
    print(ans[i]) i range(len(ans)) range len(ans) len ans print(ans[i]) print ans[i] ans i b = a-1, b-1 b-1 b ans = [0]*m [0]*m ans def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x] def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x] Find b = X[i] X[i] b pre_b = Size(b, par) Size(b, par) pre_b m = map(int, input().split()) map(int, input().split()) m def Same(x, y, par):
    return Find(x, par) == Find(y, par) def Same(x, y, par):
    return Find(x, par) == Find(y, par) Same n, m = map(int, input().split()) map(int, input().split()) n input = sys.stdin.buffer.readline sys.stdin.buffer.readline input temp = n*(n-1)//2 n*(n-1)//2 temp b = map(int, input().split()) map(int, input().split()) b a, b = X[i] X[i] a pre_a = Size(a, par) Size(a, par) pre_a X = [] [] X temp -= pre_a*pre_b pre_a*pre_b temp a, b = a-1, b-1 a-1 a def Size(x, par):
    return -par[Find(x, par)] def Size(x, par):
    return -par[Find(x, par)] Size par = [-1]* n [-1]* n par def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1 def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1 Unite rank = [0]*n [0]*n rank a, b = map(int, input().split()) map(int, input().split()) a
import sys
input = sys.stdin.buffer.readline

n, m = map(int, input().split())
X = []
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    X.append((a, b))

X.reverse()

def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x]

def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

def Same(x, y, par):
    return Find(x, par) == Find(y, par)

def Size(x, par):
    return -par[Find(x, par)]

temp = n*(n-1)//2
ans = [0]*m

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

for i in range(m):
    a, b = X[i]
    ans[i] = temp
    if Same(a, b, par):
        continue
    else:
        pre_a = Size(a, par)
        pre_b = Size(b, par)
        Unite(a, b, par, rank)
        temp -= pre_a*pre_b
        #if temp <= 0:
        #temp = 0

ans.reverse()
#print(ans)
for i in range(len(ans)):
    print(ans[i])