{$apptype console}
{$r+,q+,i+,n+,o-}

uses
    SysUtils;
var
    ans, n, m, i, j, k, u, v : longint;
    c : char;
    e : array[1..2000, 1..2000] of boolean;

begin
    reset(input, 'enemy.in');
    rewrite(output, 'enemy.out');
    readln(n, m);
    fillchar(e, sizeof(e), false);
    for i := 1 to m do begin
        read(c);
        if (c = '+') then begin
            readln(u, v);
            e[u][v] := true;
        end else begin
            ans := 0;
            readln(u);
            for j := 1 to n do begin
                if ((j = u) or (e[u][j])) then
                    continue;
                for k := 1 to n do
                    if (e[u][k]) and (e[k][j]) then begin
                        inc(ans);
                        break;
                    end;
            end;
            writeln(ans);
        end;
    end;

end.