/**
* Author: Sergey Kopeliovich (Burunduk30@gmail.com)
* Date: 2013.09.08
*/
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define pb push_back
#define mp make_pair
#define sz(a) (int)(a).size()
typedef vector <int> vi;
typedef pair <int, int> pii;
const int N = (int)3e5;
struct edge
{
int a, b, l, r;
};
typedef vector <edge> List;
int cnt[N + 1], ans[N], u[N], color[N], deg[N];
vi g[N];
void add( int a, int b )
{
g[a].pb(b), g[b].pb(a);
}
void dfs( int v, int value )
{
u[v] = 1, color[v] = value;
forn(i, sz(g[v]))
if (!u[g[v][i]])
dfs(g[v][i], value);
}
void go( int l, int r, const List &v, int vn, int add_vn ) // [l, r)
{
if (cnt[l] == cnt[r])
return; // no queries, only changes
if (!sz(v))
{
while (l < r)
ans[l++] = vn + add_vn;
return;
}
List v1;
forn(i, vn)
g[i].clear();
forn(i, sz(v))
if (v[i].a != v[i].b)
{
if (v[i].l <= l && r <= v[i].r)
add(v[i].a, v[i].b);
else if (l < v[i].r && v[i].l < r)
v1.pb(v[i]);
}
int vn1 = 0;
forn(i, vn)
u[i] = 0;
forn(i, vn)
if (!u[i])
deg[vn1] = 0, dfs(i, vn1++);
forn(i, sz(v1))
{
v1[i].a = color[v1[i].a];
v1[i].b = color[v1[i].b];
if (v1[i].a != v1[i].b)
deg[v1[i].a]++, deg[v1[i].b]++;
}
vn = vn1, vn1 = 0;
forn(i, vn)
u[i] = vn1, vn1 += (deg[i] > 0), add_vn += !deg[i];
forn(i, sz(v1))
{
v1[i].a = u[v1[i].a];
v1[i].b = u[v1[i].b];
}
int m = (l + r) / 2; // [l, m) [m, r)
go(l, m, v1, vn1, add_vn);
go(m, r, v1, vn1, add_vn);
}
int main()
{
#define NAME "connect"
assert(freopen(NAME ".in", "r", stdin));
assert(freopen(NAME ".out", "w", stdout));
map <pii, int> m;
List v;
int n, k;
scanf("%d%d", &n, &k);
forn(i, k)
{
char type;
scanf(" %c", &type);
if (type == '+' || type == '-')
{
int a, b;
scanf("%d%d", &a, &b), a--, b--;
if (a == b) // loop
{
k--, i--;
continue;
}
if (a > b)
swap(a, b);
if (type == '+')
m[mp(a, b)] = i;
else
{
int &j = m[mp(a, b)];
v.pb({a, b, j, i});
j = -1;
}
}
else
cnt[i + 1]++;
cnt[i + 1] += cnt[i];
}
forit(it, m)
if (it->second != -1)
v.pb({it->first.first, it->first.second, it->second, k});
go(0, k, v, n, 0);
forn(i, k)
if (cnt[i + 1] != cnt[i])
printf("%d\n", ans[i]);
return 0;
}
LyoqCiAqIEF1dGhvcjogU2VyZ2V5IEtvcGVsaW92aWNoIChCdXJ1bmR1azMwQGdtYWlsLmNvbSkKICogRGF0ZTogMjAxMy4wOS4wOAogKi8KCiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxjYXNzZXJ0PgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgZm9ybihpLCBuKSBmb3IgKGludCBpID0gMDsgaSA8IChpbnQpKG4pOyBpKyspCiNkZWZpbmUgZm9yaXQoaSwgYSkgZm9yIChfX3R5cGVvZigoYSkuYmVnaW4oKSkgaSA9IChhKS5iZWdpbigpOyBpICE9IChhKS5lbmQoKTsgaSsrKQojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIHN6KGEpIChpbnQpKGEpLnNpemUoKQoKdHlwZWRlZiB2ZWN0b3IgPGludD4gdmk7CnR5cGVkZWYgcGFpciA8aW50LCBpbnQ+IHBpaTsKCmNvbnN0IGludCBOID0gKGludCkzZTU7CgpzdHJ1Y3QgZWRnZQp7CiAgaW50IGEsIGIsIGwsIHI7Cn07CnR5cGVkZ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gICB9CiAgICAgIGlmIChhID4gYikKICAgICAgICBzd2FwKGEsIGIpOwoKICAgICAgaWYgKHR5cGUgPT0gJysnKQogICAgICAgIG1bbXAoYSwgYildID0gaTsKICAgICAgZWxzZQogICAgICB7CiAgICAgICAgaW50ICZqID0gbVttcChhLCBiKV07CiAgICAgICAgdi5wYih7YSwgYiwgaiwgaX0pOwogICAgICAgIGogPSAtMTsKICAgICAgfQogICAgfQogICAgZWxzZQogICAgICBjbnRbaSArIDFdKys7CiAgICBjbnRbaSArIDFdICs9IGNudFtpXTsKICB9CiAgZm9yaXQoaXQsIG0pCiAgICBpZiAoaXQtPnNlY29uZCAhPSAtMSkKICAgICAgdi5wYih7aXQtPmZpcnN0LmZpcnN0LCBpdC0+Zmlyc3Quc2Vjb25kLCBpdC0+c2Vjb25kLCBrfSk7CgogIGdvKDAsIGssIHYsIG4sIDApOwogIAogIGZvcm4oaSwgaykKICAgIGlmIChjbnRbaSArIDFdICE9IGNudFtpXSkKICAgICAgcHJpbnRmKCIlZFxuIiwgYW5zW2ldKTsKICByZXR1cm4gMDsKfQo=