import sys


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

    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1


def main():
    n, m = map(int, sys.stdin.buffer.readline().split())
    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for x in reversed(sys.stdin.buffer.readlines()):
        a, b = map(int, x.split())
        a -= 1
        b -= 1
        if uf.find(a, b):
            ans.append(ans[-1])
            continue
        ba, bb = uf.table[uf._root(a)], uf.table[uf._root(b)]
        ans.append(ans[-1] - ba*bb)
        uf.union(a, b)
    ans.reverse()
    print("\n".join(map(str, ans[1:])))


if __name__ == "__main__":
    main() import sys sys class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1 UnionFind def __init__(self, n):
        self.table = [-1] * n

     __init__ self.table = [-1] * n self.table self table [-1] * n [-1] -1 n self self n n def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

     _root stack = [] stack [] tbl = self.table tbl self.table self table while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
         tbl[x] >= 0 tbl[x] tbl x 0 stack.append(x) stack.append stack append x x = tbl[x] x tbl[x] tbl x for y in stack:
            tbl[y] = x
         y stack tbl[y] = x tbl[y] tbl y x return x x self self x x def find(self, x, y):
        return self._root(x) == self._root(y)

     find return self._root(x) == self._root(y) self._root(x) == self._root(y) self._root(x) self._root self _root x self._root(y) self._root self _root y self self x x y y def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1 union r1 = self._root(x) r1 self._root(x) self._root self _root x r2 = self._root(y) r2 self._root(y) self._root self _root y if r1 == r2:
            return
         r1 == r2 r1 r2 return d1 = self.table[r1] d1 self.table[r1] self.table self table r1 d2 = self.table[r2] d2 self.table[r2] self.table self table r2 if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1 d1 <= d2 d1 d2 self.table[r2] = r1 self.table[r2] self.table self table r2 r1 self.table[r1] += d2 self.table[r1] self.table self table r1 d2 self.table[r1] = r2 self.table[r1] self.table self table r1 r2 self.table[r2] += d1 self.table[r2] self.table self table r2 d1 self self x x y y def main():
    n, m = map(int, sys.stdin.buffer.readline().split())
    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for x in reversed(sys.stdin.buffer.readlines()):
        a, b = map(int, x.split())
        a -= 1
        b -= 1
        if uf.find(a, b):
            ans.append(ans[-1])
            continue
        ba, bb = uf.table[uf._root(a)], uf.table[uf._root(b)]
        ans.append(ans[-1] - ba*bb)
        uf.union(a, b)
    ans.reverse()
    print("\n".join(map(str, ans[1:]))) main n, m = map(int, sys.stdin.buffer.readline().split()) n map(int, sys.stdin.buffer.readline().split()) map int sys.stdin.buffer.readline().split() sys.stdin.buffer.readline().split sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline split m uf = UnionFind(n) uf UnionFind(n) UnionFind n ans = [n*(n-1)//2] ans [n*(n-1)//2] n*(n-1)//2 n*(n-1) n n-1 n 1 2 for x in reversed(sys.stdin.buffer.readlines()):
        a, b = map(int, x.split())
        a -= 1
        b -= 1
        if uf.find(a, b):
            ans.append(ans[-1])
            continue
        ba, bb = uf.table[uf._root(a)], uf.table[uf._root(b)]
        ans.append(ans[-1] - ba*bb)
        uf.union(a, b)
     x reversed(sys.stdin.buffer.readlines()) reversed sys.stdin.buffer.readlines() sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines a, b = map(int, x.split()) a map(int, x.split()) map int x.split() x.split x split b a -= 1 a 1 b -= 1 b 1 if uf.find(a, b):
            ans.append(ans[-1])
            continue
         uf.find(a, b) uf.find uf find a b ans.append(ans[-1]) ans.append ans append ans[-1] ans -1 continue ba, bb = uf.table[uf._root(a)], uf.table[uf._root(b)] ba uf.table[uf._root(a)] uf.table uf table uf._root(a) uf._root uf _root a bb uf.table[uf._root(b)] uf.table uf table uf._root(b) uf._root uf _root b ans.append(ans[-1] - ba*bb) ans.append ans append ans[-1] - ba*bb ans[-1] ans -1 ba*bb ba bb uf.union(a, b) uf.union uf union a b ans.reverse() ans.reverse ans reverse print("\n".join(map(str, ans[1:]))) print "\n".join(map(str, ans[1:])) "\n".join "\n" join map(str, ans[1:]) map str ans[1:] ans 1: 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1 class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1 UnionFind def main():
    n, m = map(int, sys.stdin.buffer.readline().split())
    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for x in reversed(sys.stdin.buffer.readlines()):
        a, b = map(int, x.split())
        a -= 1
        b -= 1
        if uf.find(a, b):
            ans.append(ans[-1])
            continue
        ba, bb = uf.table[uf._root(a)], uf.table[uf._root(b)]
        ans.append(ans[-1] - ba*bb)
        uf.union(a, b)
    ans.reverse()
    print("\n".join(map(str, ans[1:]))) def main():
    n, m = map(int, sys.stdin.buffer.readline().split())
    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for x in reversed(sys.stdin.buffer.readlines()):
        a, b = map(int, x.split())
        a -= 1
        b -= 1
        if uf.find(a, b):
            ans.append(ans[-1])
            continue
        ba, bb = uf.table[uf._root(a)], uf.table[uf._root(b)]
        ans.append(ans[-1] - ba*bb)
        uf.union(a, b)
    ans.reverse()
    print("\n".join(map(str, ans[1:]))) main
import sys


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

    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1


def main():
    n, m = map(int, sys.stdin.buffer.readline().split())
    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for x in reversed(sys.stdin.buffer.readlines()):
        a, b = map(int, x.split())
        a -= 1
        b -= 1
        if uf.find(a, b):
            ans.append(ans[-1])
            continue
        ba, bb = uf.table[uf._root(a)], uf.table[uf._root(b)]
        ans.append(ans[-1] - ba*bb)
        uf.union(a, b)
    ans.reverse()
    print("\n".join(map(str, ans[1:])))


if __name__ == "__main__":
    main()
