1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10162 (Last Digit)
* Link: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1103
*
* @author Fabian Seidl
* @author Marcel Sachse
* @version 1.0, 29/04/2009
*
* Status : Accepted
* Runtime: 0.070
*/

import java.io.*;

public class Main
{

// Precalculation: alle L¨sungen f¾r S%10 von 0 bis 99
private static int[] cache = {0,1,5,2,8,3,9,2,8,7,7,8,4,7,3,8,4,1,5,4,4,5,9,6,2,7,3,6,2,1,1,2,8,1,7,2,8,5,9,8,8,9,3,0,6,1,7,0,6,5,5,6,2,5,1,6,2,9,3,2,2,3,7,4,0,5,1,4,0,9,9,0,6,9,5,0,6,3,7,6,6,7,1,8,4,9,5,8,4,3,3,4,0,3,9,4,0,7,1,0};


public static void main(String[] args) throws Exception
{

InputStreamReader bInput = new InputStreamReader(System.in);
BufferedReader bReader = new BufferedReader(bInput);

Writer out = new BufferedWriter(new PrintWriter(System.out));

String in = bReader.readLine();

while(!in.equals("0"))
{
if(in.length()>2) in = in.substring(in.length()-2); // es m¾ssen nur die letzen zwei Ziffern beachtet werden
int n = Integer.parseInt(in);
out.write(cache[n]+"\n"); // richtige L¨sung aus cache ausgeben

in = bReader.readLine();
}

out.close();
}
}