// Arup Guha
// 11/11/2010
// Solution to 2010 SE Regional Problem F: Palindrometer

import java.util.*;

public class f {
	
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		
		// We'll process the input as Strings.
		String term = stdin.next();
		
		while (!term.equals("0")) {
			System.out.println(solve(term));
			term = stdin.next();
		}
	}
	
	// Returns the answer to the question.
	public static int solve(String term) {
	
		int extra = 0;
		
		// Try each odometer reading, one by one, in order.
		while (!isPal(term)) {
			term = getNext(term);
			extra++;
		}
		
		// This is what we had to add...
		return extra;
	}
	
	// Note: a String of 9s will never get passed to this method.
	public static String getNext(String term) {
		
		int index = term.length()-1;
		char[] copy = term.toCharArray();
		
		// Go through digits backwards.
		while (true) {
			
			// Increment this digit and we're done.
			if (copy[index] != '9') {
				copy[index]++;
				break;
			}
			
			// Carry case.
			else {
				copy[index] = '0';
				index--;
			}
			
		}
		
		return new String(copy);
	}
	
	// Returns true iff s is a palindrome.
	public static boolean isPal(String s) {
		for (int i=0; i<s.length()/2; i++)
			if (s.charAt(i) != s.charAt(s.length()-1-i))
				return false;
		return true;
	}
	
}