var
s: string;
i, Count, x: integer;
begin
ReadLn(s);
i := 1;
Count := 0;
while i <= Length(s) do begin
x := i;
while (s[i] <> ' ') and (i <= Length(s)) do Inc(i);
if s[x] = s[i-1] then Inc(Count);
while (s[i] = ' ') and (i <= Length(s)) do Inc(i);
end;
WriteLn('Количество слов с одинаковыми первым и последним символами: ', Count);
end.