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

public class enemy_ats implements Runnable {
	public static void main(String[] args) {
		new enemy_ats().run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	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();
		BitSet[] e = new BitSet[n];
		for (int i = 0; i < n; i++) {
			e[i] = new BitSet(n);
		}
		for (int i = 0; i < m; i++) {
			String code = nextToken();
			if (code.equals("+")) {
				int u = nextInt() - 1;
				int v = nextInt() - 1;
				e[u].set(v);
			} else {
				int u = nextInt() - 1;
				int ans = 0;
				BitSet candidates = new BitSet();
				for (int j = 0; j < n; j++) {
					if (!e[u].get(j)) {
						continue;
					}
					candidates.or(e[j]);
				}
				for (int j = 0; j < n; j++) {
					if (u != j && !e[u].get(j) && candidates.get(j)) {
						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);
		}
	}
}
