#木の根を得る
def root(x):
    while par[x] >= 0:
        x = par[x]
    return x

#木の併合
def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if rx > ry:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx

def size(x):
    return -par[root(x)]

def same(x, y):
    rx = root(x)
    ry = root(y)
    return rx == ry

N, M = map(int,input().split())
par = [-1]*N
K = []
for i in range(M):
    a, b = map(int, input().split())
    K.append([a-1, b-1])
K = K[::-1]

result = [0]
ans = 0
for i, j in K:
    if not same(i, j):
        a = size(i)
        b = size(j)
        unite(i, j)
        c = size(i)
        ans += c*(c-1)//2 - (a*(a-1)//2 + b*(b-1)//2)
    result.append(ans)

result = result[::-1]
for i in result[1:]:
    print(result[0] - i) def root(x):
    while par[x] >= 0:
        x = par[x]
    return x

#木の併合 root while par[x] >= 0:
        x = par[x]
     par[x] >= 0 par[x] par x 0 x = par[x] x par[x] par x return x x x x def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if rx > ry:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx unite rx = root(x) rx root(x) root x ry = root(y) ry root(y) root y if rx != ry:
        if rx > ry:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx rx != ry rx ry if rx > ry:
            rx, ry = ry, rx
         rx > ry rx ry rx, ry = ry, rx rx ry ry rx par[rx] += par[ry] par[rx] par rx par[ry] par ry par[ry] = rx par[ry] par ry rx x x y y def size(x):
    return -par[root(x)] size return -par[root(x)] -par[root(x)] par[root(x)] par root(x) root x x x def same(x, y):
    rx = root(x)
    ry = root(y)
    return rx == ry same rx = root(x) rx root(x) root x ry = root(y) ry root(y) root y return rx == ry rx == ry rx ry x x y y N, M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M par = [-1]*N par [-1]*N [-1] -1 N K = [] K [] for i in range(M):
    a, b = map(int, input().split())
    K.append([a-1, b-1]) i range(M) range M a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b K.append([a-1, b-1]) K.append K append [a-1, b-1] a-1 a 1 b-1 b 1 K = K[::-1] K K[::-1] K ::-1 -1 result = [0] result [0] 0 ans = 0 ans 0 for i, j in K:
    if not same(i, j):
        a = size(i)
        b = size(j)
        unite(i, j)
        c = size(i)
        ans += c*(c-1)//2 - (a*(a-1)//2 + b*(b-1)//2)
    result.append(ans) i j K if not same(i, j):
        a = size(i)
        b = size(j)
        unite(i, j)
        c = size(i)
        ans += c*(c-1)//2 - (a*(a-1)//2 + b*(b-1)//2)
     not same(i, j) same(i, j) same i j a = size(i) a size(i) size i b = size(j) b size(j) size j unite(i, j) unite i j c = size(i) c size(i) size i ans += c*(c-1)//2 - (a*(a-1)//2 + b*(b-1)//2) ans c*(c-1)//2 - (a*(a-1)//2 + b*(b-1)//2) c*(c-1)//2 c*(c-1) c c-1 c 1 2 a*(a-1)//2 + b*(b-1)//2 a*(a-1)//2 a*(a-1) a a-1 a 1 2 b*(b-1)//2 b*(b-1) b b-1 b 1 2 result.append(ans) result.append result append ans result = result[::-1] result result[::-1] result ::-1 -1 for i in result[1:]:
    print(result[0] - i) i result[1:] result 1: 1 print(result[0] - i) print result[0] - i result[0] result 0 i K = [] [] K b = map(int, input().split()) map(int, input().split()) b def root(x):
    while par[x] >= 0:
        x = par[x]
    return x

#木の併合 def root(x):
    while par[x] >= 0:
        x = par[x]
    return x

#木の併合 root b = size(j) size(j) b def size(x):
    return -par[root(x)] def size(x):
    return -par[root(x)] size a = size(i) size(i) a def same(x, y):
    rx = root(x)
    ry = root(y)
    return rx == ry def same(x, y):
    rx = root(x)
    ry = root(y)
    return rx == ry same M = map(int,input().split()) map(int,input().split()) M ans = 0 0 ans ans += c*(c-1)//2 - (a*(a-1)//2 + b*(b-1)//2) c*(c-1)//2 - (a*(a-1)//2 + b*(b-1)//2) ans result = [0] [0] result a, b = map(int, input().split()) map(int, input().split()) a N, M = map(int,input().split()) map(int,input().split()) N par = [-1]*N [-1]*N par K = K[::-1] K[::-1] K c = size(i) size(i) c result = result[::-1] result[::-1] result def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if rx > ry:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if rx > ry:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx unite
#木の根を得る
def root(x):
    while par[x] >= 0:
        x = par[x]
    return x

#木の併合
def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if rx > ry:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx

def size(x):
    return -par[root(x)]

def same(x, y):
    rx = root(x)
    ry = root(y)
    return rx == ry

N, M = map(int,input().split())
par = [-1]*N
K = []
for i in range(M):
    a, b = map(int, input().split())
    K.append([a-1, b-1])
K = K[::-1]

result = [0]
ans = 0
for i, j in K:
    if not same(i, j):
        a = size(i)
        b = size(j)
        unite(i, j)
        c = size(i)
        ans += c*(c-1)//2 - (a*(a-1)//2 + b*(b-1)//2)
    result.append(ans)

result = result[::-1]
for i in result[1:]:
    print(result[0] - i)