
import java.io.*;
import java.util.Scanner;

public class enemy_nn {

    static final int MAXN = 2000;
    static final int MAXM = 2000;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(new File("enemy.in"));
        PrintWriter out = new PrintWriter("enemy.out");
        int n = sc.nextInt();
        int m = sc.nextInt();
        assert (1 <= n) && (n <= MAXN);
        assert (1 <= m) && (m <= MAXM);
        boolean[][] g = new boolean[n][n];
        boolean[][] g2 = new boolean[n][n];
        for (int i = 0; i < m; i++) {
            String what = sc.next();
            assert what.equals("+") || what.equals("?");
            if (what.equals("+")) {
                int v = sc.nextInt() - 1;
                int u = sc.nextInt() - 1;
                assert 0 <= v && v < n;
                assert 0 <= u && u < n;
                assert v != u;
                assert !g[v][u];
                g[v][u] = true;
                for (int k = 0; k < n; k++) {
                    g2[v][k] |= g[v][u] && g[u][k];
                    g2[k][u] |= g[k][v] && g[v][u];
                }
            } else {
                int v = sc.nextInt() - 1;
                assert 0 <= v && v < n;
                int ans = 0;
                for (int j = 0; j < n; j++) {
                    if (j == v) {
                        continue;
                    }
                    ans += g2[v][j] && !g[v][j] ? 1 : 0;
                }
                out.println(ans);
            }
        }
        out.close();
        sc.close();
    }
}
