/*
 *	IEEEXtreme 2008
 *	Problem 7: Snapshot
 *	Ertuğ Karamatlı (http://www.ertugkaramatli.com)
 *	Doğuş Üniversitesi IEEE Student Branch
 *
 */

#include <cstdlib>
#include <cstring>
#include <string>
#include <iostream>

using namespace std;

string lowercase(string str) {

	for (int i=0; i < str.size(); i++)
		str[i] = tolower(str[i]);

	return str;
}


int main(int argc, char *argv[])
{
	string text;
	string words[256];
	
	getline (cin,text);
	
	
	char * cstr;
	cstr = new char [text.size()+1];
	strcpy (cstr, text.c_str());
	int i=0;
	char *pch = strtok(cstr," ");
	
	while (pch != NULL)
	{
		words[i]=pch;

		pch = strtok(NULL, " ");
		
		i++;
	}
	int word_count=i;
	
	string found_word[256];
	int found_pos[256]={0};
	int found_count=0;

	for (int i=1;i < argc;i++) {

		for (int j=0;j < word_count;j++) {
			if (lowercase(argv[i])==lowercase(words[j])) {
				
				bool unique=true;
				for (int i2=0;i2 < found_count;i2++) { //multi keyword check
					if (lowercase(words[j])==lowercase(found_word[i2])) {
						unique=false;
					}
				}

				if (unique) {
					found_word[found_count]=words[j];
					found_pos[found_count]=j;
				
					found_count++;
				}
			}
			
		}
		
	}
	
	if (found_count==0) {
		cout<<0;
	}
	else {
		int min_pos=999999999;
		int max_pos=-999999999;
		
		for (int i=0;i < found_count;i++) {
			min_pos=min(found_pos[i],min_pos);
			max_pos=max(found_pos[i],max_pos);
		}

		int significance=abs(max_pos-min_pos) + 1;
	
		cout<<significance;
	}

	return 0;
}
