#include <iostream>
#include <cstring>
using namespace std;

int main() 
{
	char s[256];
	int maxPalNum = 0;
	int champion = 0;
	int currentSentence = 1; 
	int palCount = 0;
	while (cin >> s)
	{
		if (s[0] == '-' && strlen(s) == 1)
			continue;
		bool endOfSentence = false;
		if (s[strlen(s)-1] == '.' || s[strlen(s)-1] == '!' || s[strlen(s)-1] == '?')
			endOfSentence = true;
		for (int i = strlen(s) - 1; i >= 0; i--)
		{
			if (!(s[i] >= 'a' && s[i] <= 'z' || s[i] >= 'A' && s[i] <= 'Z' || s[i] >= '1' && s[i] <= '9' || s[i] == '-'))
				s[i] = '\0';
			else
				break;
		}
		bool pal = true;
		
		for (int i = 0; i < strlen(s) / 2; i++)
		{
			if (s[i] >= 'A' && s[i] <= 'Z')
				s[i] += 32;
			if (s[strlen(s)-i-1] >= 'A' && s[strlen(s)-i-1] <= 'Z')
				s[strlen(s)-i-1] += 32;
			if (s[i] != s[strlen(s)-i-1])
			{
				pal = false;
				break;
			}
		}
		if (pal)
			palCount ++;
		if (endOfSentence)
		{
			if (palCount > maxPalNum)
			{
				maxPalNum = palCount;
				champion = currentSentence;
			}
			currentSentence++;
			palCount = 0;
		}
	}
	cout << champion;
	return 0;
}