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

class Ideone
{
	public static void solve(Scanner sc, PrintStream out) {
		List<Integer> list = new ArrayList<>();
		while (sc.hasNext()) list.add(sc.nextInt());
			
		int[] places = new int[list.size()];
		for (Integer i : list) ++places[i];
		
		int a = 0, b = places.length - 1;
		while (!(a == b || --places[list.get(a)] == 0)) ++a;
		while (!(a == b || --places[list.get(b)] == 0)) --b;
		
		out.println(b - a + 1);
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			Scanner scLine = new Scanner(sc.nextLine());
			solve(scLine, System.out);
			scLine.close();
		}
		
		sc.close();
	}
}