using System;

public class Pikado
{
	public static void Main()
	{
		int n = Convert.ToInt32(Console.ReadLine());
		int[] a = Translate();
		int[] b = new int[n];
		for(int i=0; i<n; i++)
		{
			b[i] = a[i];
		}
		Array.Reverse(a);
		Array.Sort(b);
		if(n==1)
		{

		}
		else if(n==2)
		{
			int p = a[0];
			a[0] = a[1];
			a[1] = p;
		}
		else
		{
			bool done = false;
			for(int i=n-1; i>=0; i--)
			{
				if(a[i]!=b[i])
				{
					int p = a[i];
					a[i] = a[Array.IndexOf(a , b[i])];
					a[Array.IndexOf(a , b[i])] = p;
					i=-1;
					done = true;
				}
			}
			if(done==false)
			{
				int p = a[0];
				a[0] = a[1];
				a[1] = p;
			}
		}
		Array.Reverse(a);		
		foreach(object x in a)
		{
			Console.Write(x + " ");
		}
	}

	public static int[] Translate()
	{
		return Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
	}
}