import sys
input = sys.stdin.readline

n,m = map(int,input().split())
edge = [tuple(map(int,input().split())) for i in range(m)]
#辺を足していくので逆順で考える
edge = edge[::-1]

par = [i for i in range(n+1)]
rank = [1] * (n+1)
size = [1] * (n+1)

###Union-Find
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

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

    #併合(Union)
def union(x, y):
    #根を探す
    x = find(x)
    y = find(y)

    #木の高さを比較し、低いほうから高いほうに根を張る
    if rank[x] < rank[y]:
        par[x] = y
        size[y] += size[x]
    else:
        par[y] = x
        size[x] += size[y]
        if rank[x] == rank[y]:
            rank[x] += 1

result = []
for i in range(m):
    a = find(edge[i][0])
    b = find(edge[i][1])
    if a == b:
        result.append(0)
    else:
        result.append(size[a]*size[b])
        union(a,b)

ans = 0
for i in range(m):
    ans += result[m-i-1]
    print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m 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 edge = [tuple(map(int,input().split())) for i in range(m)] edge [tuple(map(int,input().split())) for i in range(m)] edge = edge[::-1] edge edge[::-1] edge ::-1 -1 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 par = [i for i in range(n+1)] par [i for i in range(n+1)] rank = [1] * (n+1) rank [1] * (n+1) [1] 1 n+1 n 1 size = [1] * (n+1) size [1] * (n+1) [1] 1 n+1 n 1 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_check(x, y):
        return find(x) == find(y)

    #併合(Union) same_check 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 rank[x] < rank[y]:
        par[x] = y
        size[y] += size[x]
    else:
        par[y] = x
        size[x] += size[y]
        if rank[x] == rank[y]:
            rank[x] += 1 union x = find(x) x find(x) find x y = find(y) y find(y) find y if rank[x] < rank[y]:
        par[x] = y
        size[y] += size[x]
    else:
        par[y] = x
        size[x] += size[y]
        if rank[x] == rank[y]:
            rank[x] += 1 rank[x] < rank[y] rank[x] rank x rank[y] rank y par[x] = y par[x] par x y size[y] += size[x] size[y] size y size[x] size x par[y] = x par[y] par y x size[x] += size[y] size[x] size x size[y] size y 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 result = [] result [] for i in range(m):
    a = find(edge[i][0])
    b = find(edge[i][1])
    if a == b:
        result.append(0)
    else:
        result.append(size[a]*size[b])
        union(a,b) i range(m) range m a = find(edge[i][0]) a find(edge[i][0]) find edge[i][0] [i] edge i 0 b = find(edge[i][1]) b find(edge[i][1]) find edge[i][1] [i] edge i 1 if a == b:
        result.append(0)
    else:
        result.append(size[a]*size[b])
        union(a,b) a == b a b result.append(0) result.append result append 0 result.append(size[a]*size[b]) result.append result append size[a]*size[b] size[a] size a size[b] size b union(a,b) union a b ans = 0 ans 0 for i in range(m):
    ans += result[m-i-1]
    print(ans) i range(m) range m ans += result[m-i-1] ans result[m-i-1] result m-i-1 m-i m i 1 print(ans) print ans 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 result = [] [] result input = sys.stdin.readline sys.stdin.readline input par = [i for i in range(n+1)] [i for i in range(n+1)] par n,m = map(int,input().split()) map(int,input().split()) n edge = [tuple(map(int,input().split())) for i in range(m)] [tuple(map(int,input().split())) for i in range(m)] edge ans = 0 0 ans m = map(int,input().split()) map(int,input().split()) m b = find(edge[i][1]) find(edge[i][1]) b def same_check(x, y):
        return find(x) == find(y)

    #併合(Union) def same_check(x, y):
        return find(x) == find(y)

    #併合(Union) same_check a = find(edge[i][0]) find(edge[i][0]) a def union(x, y):
    #根を探す
    x = find(x)
    y = find(y)

    #木の高さを比較し、低いほうから高いほうに根を張る
    if rank[x] < rank[y]:
        par[x] = y
        size[y] += size[x]
    else:
        par[y] = x
        size[x] += size[y]
        if rank[x] == rank[y]:
            rank[x] += 1 def union(x, y):
    #根を探す
    x = find(x)
    y = find(y)

    #木の高さを比較し、低いほうから高いほうに根を張る
    if rank[x] < rank[y]:
        par[x] = y
        size[y] += size[x]
    else:
        par[y] = x
        size[x] += size[y]
        if rank[x] == rank[y]:
            rank[x] += 1 union size = [1] * (n+1) [1] * (n+1) size rank = [1] * (n+1) [1] * (n+1) rank edge = edge[::-1] edge[::-1] edge ans += result[m-i-1] result[m-i-1] ans
import sys
input = sys.stdin.readline

n,m = map(int,input().split())
edge = [tuple(map(int,input().split())) for i in range(m)]
#辺を足していくので逆順で考える
edge = edge[::-1]

par = [i for i in range(n+1)]
rank = [1] * (n+1)
size = [1] * (n+1)

###Union-Find
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

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

    #併合(Union)
def union(x, y):
    #根を探す
    x = find(x)
    y = find(y)

    #木の高さを比較し、低いほうから高いほうに根を張る
    if rank[x] < rank[y]:
        par[x] = y
        size[y] += size[x]
    else:
        par[y] = x
        size[x] += size[y]
        if rank[x] == rank[y]:
            rank[x] += 1

result = []
for i in range(m):
    a = find(edge[i][0])
    b = find(edge[i][1])
    if a == b:
        result.append(0)
    else:
        result.append(size[a]*size[b])
        union(a,b)

ans = 0
for i in range(m):
    ans += result[m-i-1]
    print(ans)