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

public class enemy_ats_nb implements Runnable {
    public static void main(String[] args) {
        new Thread(new enemy_ats_nb()).start();
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

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

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();

        assert (1 <= n && n <= MAXN);
        assert (1 <= m && m <= MAXM);

        boolean[][] enemy = new boolean[n][n];
        boolean[][] maybeFriend = new boolean[n][n];
        for (int i = 0; i < m; i++) {
            String code = nextToken();
            assert (code.equals("+") || code.equals("?"));

            if (code.charAt(0) == '+') {
                int u = nextInt() - 1;
                int v = nextInt() - 1;

                assert (0 <= u && u < n);
                assert (0 <= v && v < n);
                assert (u != v);
                assert (!enemy[u][v]);

                enemy[u][v] = true;
                for (int k = 0; k < n; k++) {
                    if (enemy[v][k]) {
                        maybeFriend[u][k] = true;
                    }
                    if (enemy[k][u]) {
                        maybeFriend[k][v] = true;
                    }
                }
            } else {
                int u = nextInt() - 1;
                assert (0 <= u && u < n);
                int ans = 0;
                for (int k = 0; k < n; k++) {
                    if (k != u && maybeFriend[u][k] && !enemy[u][k]) {
                        ans++;
                    }
                }
                out.println(ans);
            }
        }
    }

    public void run() {
        try {
            Locale.setDefault(Locale.US);
            br = new BufferedReader(new FileReader("enemy.in"));
            out = new PrintWriter("enemy.out");

            solve();

            out.close();
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}

