from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]

data = [stdin.readline().rstrip().split() for _ in range(M)]



island = list(range(N))

counts = [1] * N

total = int((N * (N - 1)) / 2)

result = []



for c in reversed(data):

    ref0 = int(c[0]) - 1

    while island[ref0] != ref0:

        ref0 = island[ref0]

    ref1 = int(c[1]) - 1

    while island[ref1] != ref1:

        ref1 = island[ref1]



    if ref0 == ref1:

        result.append(0);

    else:

        island[max(ref0,ref1)] = min(ref0, ref1)

        result.append(counts[ref0] * counts[ref1]);

        counts[min(ref0,ref1)] = counts[ref0] + counts[ref1]



res = [total]

for r in result:

    res.append((res[-1] - r))



print(('\n'.join(reversed([str(x) for x in res][:-1]))))

from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]

data = [stdin.readline().rstrip().split() for _ in range(M)]



island = list(range(N))

counts = [1] * N

total = int((N * (N - 1)) / 2)

result = []



for c in reversed(data):

    ref0 = int(c[0]) - 1

    while island[ref0] != ref0:

        ref0 = island[ref0]

    ref1 = int(c[1]) - 1

    while island[ref1] != ref1:

        ref1 = island[ref1]



    if ref0 == ref1:

        root = min(ref0, ref1)

        pair = max(ref0, ref1)

        island[int(c[0]) - 1] = root

        island[int(c[1]) - 1] = root

        island[pair] = root

        result.append(0);

    else:

        root = min(ref0, ref1)

        pair = max(ref0, ref1)

        island[int(c[0]) - 1] = root

        island[int(c[1]) - 1] = root

        island[pair] = root

        result.append(counts[ref0] * counts[ref1]);

        counts[root] = counts[ref0] + counts[ref1]



res = [total]

for r in result:

    res.append((res[-1] - r))



print(('\n'.join(reversed([str(x) for x in res][:-1]))))

from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip().split() for _ in range(M)]
island = list(range(N))
counts = [1] * N
total = int((N * (N - 1)) / 2)
result = []
for c in reversed(data):
    ref0 = int(c[0]) - 1
    while island[ref0] != ref0:
        ref0 = island[ref0]
    ref1 = int(c[1]) - 1
    while island[ref1] != ref1:
        ref1 = island[ref1]
    if ref0 == ref1:
        result.append(0)
    else:
        island[max(ref0, ref1)] = min(ref0, ref1)
        result.append(counts[ref0] * counts[ref1])
        counts[min(ref0, ref1)] = counts[ref0] + counts[ref1]
res = [total]
for r in result:
    res.append((res[-1] - r))
print(("\n".join(reversed([str(x) for x in res][:-1]))))

from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip().split() for _ in range(M)]
island = list(range(N))
counts = [1] * N
total = int((N * (N - 1)) / 2)
result = []
for c in reversed(data):
    ref0 = int(c[0]) - 1
    while island[ref0] != ref0:
        ref0 = island[ref0]
    ref1 = int(c[1]) - 1
    while island[ref1] != ref1:
        ref1 = island[ref1]
    if ref0 == ref1:
        root = min(ref0, ref1)
        pair = max(ref0, ref1)
        island[int(c[0]) - 1] = root
        island[int(c[1]) - 1] = root
        island[pair] = root
        result.append(0)
    else:
        root = min(ref0, ref1)
        pair = max(ref0, ref1)
        island[int(c[0]) - 1] = root
        island[int(c[1]) - 1] = root
        island[pair] = root
        result.append(counts[ref0] * counts[ref1])
        counts[root] = counts[ref0] + counts[ref1]
res = [total]
for r in result:
    res.append((res[-1] - r))
print(("\n".join(reversed([str(x) for x in res][:-1]))))

+        root = min(ref0, ref1) +        pair = max(ref0, ref1) +        island[int(c[0]) - 1] = root +        island[int(c[1]) - 1] = root +        island[pair] = root -        island[max(ref0, ref1)] = min(ref0, ref1) +        root = min(ref0, ref1) +        pair = max(ref0, ref1) +        island[int(c[0]) - 1] = root +        island[int(c[1]) - 1] = root +        island[pair] = root -        counts[min(ref0, ref1)] = counts[ref0] + counts[ref1] +        counts[root] = counts[ref0] + counts[ref1]