public static void main(String[] args)
	{
		if (args.length < 1)
		{
			System.err.println("Usage: java FollowPointers input-file");
			return;
		}

		String filename = args[0];
		Scanner scanner = null;
		int[] array = null;
		int size = 0;
		try
		{
			scanner = new Scanner(new FileInputStream(filename));
			int i = 0;
			while (scanner.hasNextLine())
			{
				String line = scanner.nextLine(); // only read 2 lines
				if (null == line || line.length() == 0)
					break;
				if (0 == i)
				{
					size = Integer.parseInt(line);
					array = new int[size];
				}
				else
				{
					int val = Integer.parseInt(line);
					array[i-1] = val;
				}
				i++;
			}
		
			if (0 == array.length)
			{
				System.err.println("Cannot process pointers");
				return;
			}
			
			int result = followPointers(array);
			System.out.println(result);
		}
		catch(Exception e)
		{
			System.err.println("Error processing input file " + filename);
			e.printStackTrace();
		}
		finally
		{
			if (null != scanner)
			{
				scanner.close();
			}
		}
	}