import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

\

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 親が同じか判別
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 根を繋ぎ直す
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 親が同じか判別
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 連結成分の大きさを返す
    def size(self, x):
        return -self.parents[self.find(x)]


def resolve():
    n, m = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(m)][::-1]
    uf = UnionFind(n)

    res = [(n * (n - 1)) // 2]
    for a, b in AB:
        if not uf.same(a - 1, b - 1):
            pre1 = uf.size(a - 1)
            pre2 = uf.size(b - 1)
            pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2

            uf.union(a - 1, b - 1)
            now = uf.size(a - 1)
            now_score = (now * (now - 1)) // 2

            res.append(res[-1] + pre_score - now_score)
        else:
            res.append(res[-1])

    for i in reversed(range(m)):
        print(res[i])


if __name__ == '__main__':
    resolve() import sys sys sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline f_inf = float('inf') f_inf float('inf') float 'inf' mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 親が同じか判別
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 根を繋ぎ直す
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 親が同じか判別
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 連結成分の大きさを返す
    def size(self, x):
        return -self.parents[self.find(x)] UnionFind def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 親が同じか判別
     __init__ self.n = n self.n self n n self.parents = [-1] * n self.parents self parents [-1] * n [-1] -1 n self self n n def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 根を繋ぎ直す
     find if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 根を繋ぎ直す
     self.parents[x] < 0 self.parents[x] self.parents self parents x 0 return x x self.parents[x] = self.find(self.parents[x]) self.parents[x] self.parents self parents x self.find(self.parents[x]) self.find self find self.parents[x] self.parents self parents x return self.parents[x] self.parents[x] self.parents self parents x self self x x def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 親が同じか判別
     union x = self.find(x) x self.find(x) self.find self find x y = self.find(y) y self.find(y) self.find self find y if x == y:
            return
         x == y x y return if self.parents[x] > self.parents[y]:
            x, y = y, x
         self.parents[x] > self.parents[y] self.parents[x] self.parents self parents x self.parents[y] self.parents self parents y x, y = y, x x y y x self.parents[x] += self.parents[y] self.parents[x] self.parents self parents x self.parents[y] self.parents self parents y self.parents[y] = x self.parents[y] self.parents self parents y x self self x x y y def same(self, x, y):
        return self.find(x) == self.find(y)

    # 連結成分の大きさを返す
     same return self.find(x) == self.find(y) self.find(x) == self.find(y) self.find(x) self.find self find x self.find(y) self.find self find y self self x x y y def size(self, x):
        return -self.parents[self.find(x)] size return -self.parents[self.find(x)] -self.parents[self.find(x)] self.parents[self.find(x)] self.parents self parents self.find(x) self.find self find x self self x x def resolve():
    n, m = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(m)][::-1]
    uf = UnionFind(n)

    res = [(n * (n - 1)) // 2]
    for a, b in AB:
        if not uf.same(a - 1, b - 1):
            pre1 = uf.size(a - 1)
            pre2 = uf.size(b - 1)
            pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2

            uf.union(a - 1, b - 1)
            now = uf.size(a - 1)
            now_score = (now * (now - 1)) // 2

            res.append(res[-1] + pre_score - now_score)
        else:
            res.append(res[-1])

    for i in reversed(range(m)):
        print(res[i]) resolve 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 AB = [list(map(int, input().split())) for _ in range(m)][::-1] AB [list(map(int, input().split())) for _ in range(m)][::-1] [list(map(int, input().split())) for _ in range(m)] ::-1 -1 uf = UnionFind(n) uf UnionFind(n) UnionFind n res = [(n * (n - 1)) // 2] res [(n * (n - 1)) // 2] (n * (n - 1)) // 2 n * (n - 1) n n - 1 n 1 2 for a, b in AB:
        if not uf.same(a - 1, b - 1):
            pre1 = uf.size(a - 1)
            pre2 = uf.size(b - 1)
            pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2

            uf.union(a - 1, b - 1)
            now = uf.size(a - 1)
            now_score = (now * (now - 1)) // 2

            res.append(res[-1] + pre_score - now_score)
        else:
            res.append(res[-1])

     a b AB if not uf.same(a - 1, b - 1):
            pre1 = uf.size(a - 1)
            pre2 = uf.size(b - 1)
            pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2

            uf.union(a - 1, b - 1)
            now = uf.size(a - 1)
            now_score = (now * (now - 1)) // 2

            res.append(res[-1] + pre_score - now_score)
        else:
            res.append(res[-1])

     not uf.same(a - 1, b - 1) uf.same(a - 1, b - 1) uf.same uf same a - 1 a 1 b - 1 b 1 pre1 = uf.size(a - 1) pre1 uf.size(a - 1) uf.size uf size a - 1 a 1 pre2 = uf.size(b - 1) pre2 uf.size(b - 1) uf.size uf size b - 1 b 1 pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2 pre_score (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2 (pre1 * (pre1 - 1)) // 2 pre1 * (pre1 - 1) pre1 pre1 - 1 pre1 1 2 (pre2 * (pre2 - 1)) // 2 pre2 * (pre2 - 1) pre2 pre2 - 1 pre2 1 2 uf.union(a - 1, b - 1) uf.union uf union a - 1 a 1 b - 1 b 1 now = uf.size(a - 1) now uf.size(a - 1) uf.size uf size a - 1 a 1 now_score = (now * (now - 1)) // 2 now_score (now * (now - 1)) // 2 now * (now - 1) now now - 1 now 1 2 res.append(res[-1] + pre_score - now_score) res.append res append res[-1] + pre_score - now_score res[-1] + pre_score res[-1] res -1 pre_score now_score res.append(res[-1]) res.append res append res[-1] res -1 for i in reversed(range(m)):
        print(res[i]) i reversed(range(m)) reversed range(m) range m print(res[i]) print res[i] res i if __name__ == '__main__':
    resolve() __name__ == '__main__' __name__ '__main__' resolve() resolve f_inf = float('inf') float('inf') f_inf mod = 10 ** 9 + 7 10 ** 9 + 7 mod def resolve():
    n, m = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(m)][::-1]
    uf = UnionFind(n)

    res = [(n * (n - 1)) // 2]
    for a, b in AB:
        if not uf.same(a - 1, b - 1):
            pre1 = uf.size(a - 1)
            pre2 = uf.size(b - 1)
            pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2

            uf.union(a - 1, b - 1)
            now = uf.size(a - 1)
            now_score = (now * (now - 1)) // 2

            res.append(res[-1] + pre_score - now_score)
        else:
            res.append(res[-1])

    for i in reversed(range(m)):
        print(res[i]) def resolve():
    n, m = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(m)][::-1]
    uf = UnionFind(n)

    res = [(n * (n - 1)) // 2]
    for a, b in AB:
        if not uf.same(a - 1, b - 1):
            pre1 = uf.size(a - 1)
            pre2 = uf.size(b - 1)
            pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2

            uf.union(a - 1, b - 1)
            now = uf.size(a - 1)
            now_score = (now * (now - 1)) // 2

            res.append(res[-1] + pre_score - now_score)
        else:
            res.append(res[-1])

    for i in reversed(range(m)):
        print(res[i]) resolve class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 親が同じか判別
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 根を繋ぎ直す
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 親が同じか判別
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 連結成分の大きさを返す
    def size(self, x):
        return -self.parents[self.find(x)] class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 親が同じか判別
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 根を繋ぎ直す
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 親が同じか判別
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 連結成分の大きさを返す
    def size(self, x):
        return -self.parents[self.find(x)] UnionFind input = sys.stdin.readline sys.stdin.readline input
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

\

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 親が同じか判別
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 根を繋ぎ直す
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 親が同じか判別
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 連結成分の大きさを返す
    def size(self, x):
        return -self.parents[self.find(x)]


def resolve():
    n, m = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(m)][::-1]
    uf = UnionFind(n)

    res = [(n * (n - 1)) // 2]
    for a, b in AB:
        if not uf.same(a - 1, b - 1):
            pre1 = uf.size(a - 1)
            pre2 = uf.size(b - 1)
            pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2

            uf.union(a - 1, b - 1)
            now = uf.size(a - 1)
            now_score = (now * (now - 1)) // 2

            res.append(res[-1] + pre_score - now_score)
        else:
            res.append(res[-1])

    for i in reversed(range(m)):
        print(res[i])


if __name__ == '__main__':
    resolve()
