import java.util.*;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int first = Integer.MAX_VALUE, second = Integer.MAX_VALUE;

        for (int i = 0, x; i < N; ++i) {
            x = sc.nextInt();
            if (x < first) {
                second = first;
                first = x;
            } else if (x > first && x < second) {
                second = x;
            }
        }

        if (second == Integer.MAX_VALUE)
            System.out.println("NO");
        else
            System.out.println(second);
    }

}


import java.util.*;
import java.io.*;
public class Main {
    public static void main (String [] args) throws IOException {
        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int [] nums = new int[n];
        args = br.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(args[i]);
        }
        Arrays.sort(nums);
        int min = nums[0];
        for (int i = 1; i < n; i++) {
            if (nums[i]>min) {
                System.out.println(nums[i]); return;
            }
        }
        System.out.println("NO");
    }
}


import java.util.*;

public class CDF22_A {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i=0; i<N; i++)
            A[i] = sc.nextInt();
        Arrays.sort(A);
        int i = 0;
        while (i < A.length && A[i] == A[0]) i++;
        System.out.println(i == A.length ? "NO" : A[i]);
        sc.close();
    }
}


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

public class A {

    public static void main(String[] args) {
        Scanner s = new Scanner(new InputStreamReader(System.in));
        int n = s.nextInt();
        if (n == 1) {
            System.out.println("NO");
            System.exit(0);
        }
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = s.nextInt();
        }
        Arrays.sort(nums);
        int x = 1;
        while (x < n && nums[x] == nums[x - 1])
            x++;
        if (x == n) {
            System.out.println("NO");
            System.exit(0);
        } else {
            System.out.println(nums[x]);
            System.exit(0);
        }

    }
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws Exception {
        //System.setIn(new FileInputStream("1"));
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        solve();

        in.close();
        out.close();
    }

    private static void solve() throws Exception {
        int n = nextInt();
        boolean[] use = new boolean[500];
        ArrayList<Integer> a = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            int v = nextInt();
            if (!use[250 + v]) {
                use[250 + v] = true;
                a.add(v);
            }
        }
        Collections.sort(a);
        if (a.size() < 2) {
            out.println("NO");
        } else {
            out.println(a.get(1));
        }
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer st;

    static String nextString() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(nextString());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(nextString());
    }
}


import java.util.*;

public class Main
{
 public static void main(String[] args)
 {
  Scanner keyboard = new Scanner(System.in);
  int size = Integer.parseInt(keyboard.nextLine());
  int[] arr = new int[size];
  int i = 0;
  while( size != 0 )
  {
   arr[i] = keyboard.nextInt();
   size--;
   i++;
  }

  if( arr.length == 1 )
  {
   System.out.println("NO");
  }
  else
  {
   Arrays.sort(arr);
   boolean val = false;
   int ans = 0;
   for ( i = 0; i< arr.length-1 ; i++ )
   {
    if( arr[i] != arr[i+1] )
    {
     val = true;
     ans = arr[i+1];
     System.out.println(ans);
     i = arr.length;
    }
    else if( i == arr.length-2 ) //val == false
    {
     System.out.println("NO");
    }
   }
  }
 }
}


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

public class A implements Runnable {
	public static void main(String[] args) {
		new A().run();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		boolean eof;
		String buf;

		public FastScanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
			nextToken();
		}

		public FastScanner(InputStream stream) {
			br = new BufferedReader(new InputStreamReader(stream));
			nextToken();
		}

		String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					eof = true;
					break;
				}
			}
			String ret = buf;
			buf = eof ? "-1" : st.nextToken();
			return ret;
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}

		void close() {
			try {
				br.close();
			} catch (Exception e) {

			}
		}

		boolean isEOF() {
			return eof;
		}
	}

	FastScanner sc;
	PrintWriter out;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			sc = new FastScanner(System.in);
			out = new PrintWriter(System.out);
			solve();
			sc.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	int nextInt() {
		return sc.nextInt();
	}

	String nextToken() {
		return sc.nextToken();
	}

	long nextLong() {
		return sc.nextLong();
	}

	double nextDouble() {
		return sc.nextDouble();
	}

	void solve() {
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		Arrays.sort(a);
		int i = 1;
		while (i < n && a[i] == a[i - 1]) {
			++i;
		}
		if (i >= n) {
			out.println("NO");
		} else {
			out.println(a[i]);
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;

/* Template for TopCoder and ACMonline. */
public class A {
    private static StreamTokenizer in = null;
    private static PrintWriter out = null;

    static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

    static double nextDouble() throws IOException {
        in.nextToken();
        return (double) in.nval;
    }

    static String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }

    public static void main(String[] args) throws IOException {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        // Here is the solution:
        new A().solve();
        out.flush();
    }

    public void solve() throws IOException {
        int n = nextInt();
        int min = Integer.MAX_VALUE;
        int res = Integer.MAX_VALUE;
        for (int i=0; i<n; ++i) {
            int d = nextInt();
            if (d<min) {
                res = min;
                min = d;
            } else if (d>min && d<res)
                res = d;
        }
        if (res == Integer.MAX_VALUE)
            out.println("NO");
        else
            out.println(res);
    }
}


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

public class Main implements Runnable {
	public void solution() throws IOException {
		int n = in.nextInt();
		int[] a = new int[n];
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n; ++i) {
			a[i] = in.nextInt();
			if (a[i] < min) {
				min = a[i];
			}
		}
		int res = Integer.MAX_VALUE;
		for (int i = 0; i < n; ++i) {
			if (a[i] != min && a[i] < res) {
				res = a[i];
			}
		}
		if (res == Integer.MAX_VALUE) {
			out.println("NO");
		} else {
			out.println(res);
		}
	}

	public void run() {
		try {
			solution();
			in.reader.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private class Scanner {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public Scanner(Reader reader) {
			this.reader = new BufferedReader(reader);
			this.tokenizer = new StringTokenizer("");
		}

		public boolean hasNext() throws IOException {
			while (!tokenizer.hasMoreTokens()) {
				String next = reader.readLine();
				if (next == null) {
					return false;
				}
				tokenizer = new StringTokenizer(next);
			}
			return true;
		}

		public String next() throws IOException {
			hasNext();
			return tokenizer.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public String nextLine() throws IOException {
			tokenizer = new StringTokenizer("");
			return reader.readLine();
		}
	}

	public static void main(String[] args) throws IOException {
		new Thread(null, new Main(), "", 1 << 28).start();
	}
	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	Scanner in = new Scanner(new InputStreamReader(System.in));
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayDeque;
import java.util.Arrays;

public class Main {
	private static StreamTokenizer in;
	private static PrintWriter out;

	private static int nextInt() throws Exception {
		in.nextToken();
		return (int)in.nval;
	}

	private static String nextString() throws Exception {
		in.nextToken();
		return in.sval;
	}

	public static void main(String[] args) throws Exception {
		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		out = new PrintWriter(System.out);

		int n = nextInt();
		int[] a = new int[n];
		for (int i=0; i<n; i++)
			a[i] = nextInt();
		Arrays.sort(a);
		int u = a[0];
		for (int i=0; i<n; i++)
			if (a[i]>u) {
				out.println(a[i]);
				out.flush();
				return;
			}
		out.println("NO");
		out.flush();
	}
}


//package round22;

import java.io.PrintWriter;
import java.io.StringReader;
import java.util.Arrays;
import java.util.Scanner;

public class A {
	private Scanner in;
	private PrintWriter out;
//	private String INPUT = "5 1 2 3 1 1";
	private String INPUT = "";

	public void solve()
	{
		int n = ni();
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = ni();
		}
		Arrays.sort(a);
		for(int i = 1;i < n;i++){
			if(a[i] > a[i - 1]){
				out.println(a[i]);
				return;
			}
		}
		out.println("NO");
	}

	public void run() throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new StringReader(INPUT));
		out = new PrintWriter(System.out);

		solve();
		out.flush();
	}

	public static void main(String[] args) throws Exception
	{
		new A().run();
	}

	private int ni() { return Integer.parseInt(in.next()); }
	private static void tr(Object... o) { System.out.println(o.length == 1 ? o[0] : Arrays.toString(o)); }
}


import java.util.*;
import java.lang.*;
import java.math.*;

public class Main{

    Scanner sc=new Scanner(System.in);

    void run(){
        int n = sc.nextInt();

        int x[] = new int [n];

        for (int i=0;i<n;i++)
            x[i] = sc.nextInt();

        java.util.Arrays.sort(x);

        int i = 0;

        for(i=0;i<n-1;i++) {
            if (x[i] != x[i+1]) {
                System.out.println( x[i+1] );
                return;
            }
        }

        System.out.println("NO");

        return;

    }

    public static void main(String[] args){
        new Main().run();
    }
}


import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		TreeSet<Integer> set = new TreeSet<Integer>();

		for(int i=0;i<n;i++){
			set.add(sc.nextInt());
		}

		if(set.size() >= 2)
			System.out.println(set.toArray()[1]);
		else
			System.out.println("NO");
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class One {
	InputStreamReader inp = new InputStreamReader(System.in);
	BufferedReader in = new BufferedReader(inp);
	boolean test = false;

	// String[] inData = { "4", "A", "B", "C", "D", "A-B 1:1", "A-C 2:2",
	// "A-D 1:0", "B-C 1:0", "B-D 0:3", "C-D 0:3" };
	String[] inData = { "4","1 1 2" };

	static int id = -1;

	public String readLine() throws IOException {
		id++;
		if (test)
			return inData[id];
		else
			return in.readLine();
	}

	public void solve() throws Exception {
		readLine();
		String readLine = readLine();

		String[] split = readLine.split(" ");
		List<Integer> ints = new ArrayList<Integer>();

		for (int i = 0; i < split.length; i++) {
			ints.add(Integer.valueOf(split[i]));
		}

		Collections.sort(ints);
		Integer object = ints.get(0);
		for (int i = 0; i < split.length; i++) {
			if(ints.get(i).compareTo(object) > 0){
				System.out.println(ints.get(i));
				return;
			}
		}
		System.out.println("NO");
	}

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

		new One().solve();

	}
}


import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	// static int INF=1<<28;
	//int x,y;
	static int sum=0;
    //static ArrayList<Integer> lis = new ArrayList<Integer>();

	public static void main(String[] args)throws Exception{
	//	Scanner sc =new Scanner(new File("input.txt"));
		Scanner sc =new Scanner(System.in);
     // File file = new File("prime2.txt");
	//	PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
	//	sc.useDelimiter("(\\s)+|[,]");
	//	ArrayList<Integer> lis = new ArrayList<Integer>();
	//ArrayList<String> lis = new ArrayList<String>();
	//System.out.println();
    //  for(int i=0;i<;i++)

   while(sc.hasNext()){

	 int n=ni(sc),x[]=new int[n+1];
	 for(int i=1;i<=n;i++)x[i]=ni(sc);
	 sort(x);
	 if(x[n]==1){x[n]=2;for(int i=1;i<=n;i++)System.out.print(x[i]+" ");}
	 else{x[0]=1;
	 for(int i=0;i<n;i++)System.out.print(x[i]+" ");
	 }

   }

	}

	static void db(Object... os){
	         System.err.println(Arrays.deepToString(os));
	}

	static int ni(Scanner in){
		return in.nextInt();
	}

}


import java.io.*;
import java.util.*;
import java.math.*;

public class TaskA {
	void Run() throws IOException {
		int n=ReadInt();
		int[] arr=new int[n];
		for(int i=0;i<n;++i)
			arr[i]=ReadInt();
		Arrays.sort(arr);
		boolean one=true;
		for(int x : arr)
			if(x!=1) {
				one=false;
				break;
			}
		if(one) {
			for(int i=1;i<n;++i)
				output.print("1 ");
			output.print("2");
			return;
		}
		int prev=1;
		for(int x : arr)
			if(x==prev) {
				output.print(prev);
				output.print(" ");
			} else {
				output.print(prev);
				output.print(" ");
				prev=x;
			}
	}

	public static void main(String[] args) throws IOException {
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		Reader reader;
		reader=oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
		input=new BufferedReader(reader);
		Writer writer=new OutputStreamWriter(System.out);
		writer=new BufferedWriter(writer);
		output=new PrintWriter(writer);
		new TaskA().Run();
		output.close();
	}

	static int ReadInt() throws IOException {
		return Integer.parseInt(ReadString());
	}

	static long ReadLong() throws IOException {
		return Long.parseLong(ReadString());
	}

	static String ReadString() throws IOException {
		while(tokenizer==null || !tokenizer.hasMoreTokens())
			tokenizer=new StringTokenizer(input.readLine());
		return tokenizer.nextToken();
	}

	static StringTokenizer tokenizer;
	static BufferedReader input;
	static PrintWriter output;
}


import javax.sound.sampled.Line;
import java.awt.Point;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.*;
import java.math.BigInteger;
import static java.math.BigInteger.*;
import java.util.*;
public class A{

    void solve()throws Exception
    {
      int n=nextInt();
      int[]a=new int[n];
        for(int i=0;i<n;i++)
            a[i]=nextInt();
        Arrays.sort(a);
        int[]res=new int[n];
        for(int i=0;i<n;i++)
        {
            if(i==0)
                res[i]=1;
            else
                res[i]=a[i-1];
        }
        if(a[n-1]==1)
            res[n-1]=2;
        for(int i=0;i<n;i++)
        {
            if(i==n-1)
                writer.println(res[i]);
            else
                writer.print(res[i]+" ");

        }

    }
     ////////////
    BufferedReader reader;
    PrintWriter writer;
    StringTokenizer stk;
    void run()throws Exception
    {
        reader=new BufferedReader(new InputStreamReader(System.in));
        stk=null;
        writer=new PrintWriter(new PrintWriter(System.out));
        solve();
        reader.close();
        writer.close();
    }
    int nextInt()throws Exception
    {
        return Integer.parseInt(nextToken());
    }

    long nextLong()throws Exception
    {
        return Long.parseLong(nextToken());

    }
    double nextDouble()throws Exception
    {
        return Double.parseDouble(nextToken());

    }

    String nextString()throws Exception
    {
        return nextToken();
    }
    String nextLine()throws Exception
    {
        return reader.readLine();
    }
    String nextToken()throws Exception
    {
        if(stk==null || !stk.hasMoreTokens())
        {
            stk=new StringTokenizer(nextLine());
            return nextToken();

        }
        return stk.nextToken();
    }

    public static void main(String[]args) throws Exception
    {
        new A().run();
    }

}


import java.io.*;
import java.util.*;
import java.math.*;

//created at 6:06 PM 12/9/11 by Abrackadabra

public class A {
    int IOMode = 0; //0 - consoleIO, 1 - <taskName>.in/out, 2 - input.txt/output.txt, 3 - test case generator
    String taskName = "";

    void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        Arrays.sort(a);
        int z = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] != 1) z++;
        }
        if (z == 0 && n > 1) a[n - 2] = 2;
        if (n == 1 && a[0] == 1) {
            out.println(2);
            return;
        }
        out.print("1 ");
        for (int i = 0; i < n - 1; i++)
            out.print(a[i] + " ");
    }

    public static void main(String[] args) throws IOException {
        if (args.length > 0 && args[0].equals("Abra")) debugMode = true;
        new A().run();
    }

    long startTime = System.nanoTime(), tempTime = startTime, finishTime = startTime;
    long startMem = Runtime.getRuntime().totalMemory(), finishMem = startMem;

    void run() throws IOException {
        init();
        if (debugMode) {
            con.println("Start");
            con.println("Console output:");
        }
        solve();
        finishTime = System.nanoTime();
        finishMem = Runtime.getRuntime().totalMemory();
        out.flush();
        if (debugMode) {
            int maxSymbols = 1000, c = 0;
            BufferedReader tbr = new BufferedReader(new FileReader("input.txt"));
            char[] a = new char[maxSymbols];
            tbr.read(a);
            if (a[0] != 0) {
                con.println();
                con.println("File input:");
                con.print(a);
            }
            boolean left = true;
            for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;
            if (left) con.println("...");
            else con.println();
            tbr = new BufferedReader(new FileReader("output.txt"));
            a = new char[maxSymbols];
            tbr.read(a);
            if (a[0] != 0) {
                con.println();
                con.println("File output:");
                con.print(a);
            }
            left = true;
            for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;
            if (left) con.println("...");
            else con.println();
            con.println("Time passed:  " + (finishTime - startTime) / 1000000000.0 + " sec");
            con.println("Memory used:  " + (finishMem - startMem) + " bytes");
            con.println("Total memory: " + Runtime.getRuntime().totalMemory() + " bytes");
        }
    }

    boolean tick(double x) {
        if (System.nanoTime() - tempTime > x) {
            tempTime = System.nanoTime();
            con.println("Tick at " + (tempTime - startTime) / 1000000000 + " sec");
            con.print("   ");
            return true;
        }
        return false;
    }

    void printTime() {
        con.println((System.nanoTime() - tempTime) + " nanos passed");
        tempTime = System.nanoTime();
    }

    static boolean debugMode = false;
    PrintStream con = System.out;

    void init() throws IOException {
        if (debugMode && IOMode != 3) {
            br = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter(new FileWriter("output.txt"));
        } else
            switch (IOMode) {
                case 0:
                    br = new BufferedReader(new InputStreamReader(System.in));
                    out = new PrintWriter(System.out);
                    break;
                case 1:
                    br = new BufferedReader(new FileReader(taskName + ".in"));
                    out = new PrintWriter(new FileWriter(taskName + ".out"));
                    break;
                case 2:
                    br = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter(new FileWriter("output.txt"));
                    break;
                case 3:
                    out = new PrintWriter(new FileWriter("input.txt"));
                    break;
            }
    }

    BufferedReader br;
    PrintWriter out;
    StringTokenizer in;

    boolean hasMoreTokens() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) return false;
            in = new StringTokenizer(line);
        }
        return true;
    }

    String nextString() throws IOException {
        return hasMoreTokens() ? in.nextToken() : null;
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextString());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextString());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextString());
    }
}


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

public class c {
	public static void main(String[] args)
			throws IOException {
		BufferedReader r =
				new BufferedReader(new InputStreamReader(System.in), 1);
		String s = r.readLine();
		int n = Integer.parseInt(s);
		String s2 = r.readLine();
		StringTokenizer st = new StringTokenizer(s2," ");
		int a[] = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(st.nextToken());
		Arrays.sort(a);
		if (a[n - 1] == 1) a[n - 1] = 2;
		else {a[n - 1] = 1; Arrays.sort(a);}
		for (int i = 0; i < n; i++)
			System.out.println(a[i]);
	}
}


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

public class A {

	public A () throws IOException {
		String input = r.readLine();
		int N = Integer.parseInt(input);
		int [] A = new int [N];
		input = r.readLine();
		String [] S = input.split(" ");
		for (int i = 0; i < N; ++i)
			A[i] = Integer.parseInt(S[i]);
		solve(N, A);
	}

	public void solve (int N, int [] A) {
		t = millis();
		Arrays.sort(A);
		if (A[N-1] > 1) A[N-1] = 1;
		else A[N-1] = 2;
		Arrays.sort(A);
		System.out.print(A[0]);
		for (int i = 1; i < N; ++i)
			System.out.print(" " + A[i]);
		System.out.println();
	}

	////////////////////////////////////////////////////////////////////////////////////

	static BufferedReader r;
	static long t;

	static void print2 (Object o) {
		System.out.println(o);
	}

	static void print (Object o) {
		print2(o);
		//print2((millis() - t) / 1000.0);
		System.exit(0);
	}

	static void run () throws IOException {
		r = new BufferedReader(new InputStreamReader(System.in));
		new A();
	}

	public static void main(String[] args) throws IOException {
		run();
	}

	static long millis() {
		return System.currentTimeMillis();
	}
}


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		int n = nextInt();
		int m[] = new int[n];
		for(int i = 0; i < n; i++)
			m[i] = nextInt();
		sort(m);
		m[n - 1] = m[n - 1] != 1 ? 1 : 2;
		sort(m);
		for(int i = 0; i < n; i++){
			if(i != 0) out.print(" ");
			out.print(m[i]);
		}
		out.println();
		in.close();
		out.close();
	}

	void chk(boolean b) {
		if (b)
			return;
		System.out.println(new Error().getStackTrace()[1]);
		exit(999);
	}
	void deb(String fmt, Object... args) {
		System.out.printf(Locale.US, fmt + "%n", args);
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A135 {
	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(r.readLine());

		int[] ar = new int[n];
		StringTokenizer st = new StringTokenizer(r.readLine());
		for (int x = 0; x < n; x++) {
			ar[x] = Integer.parseInt(st.nextToken());
		}
		Arrays.sort(ar);
		if (n == 1) {

			System.out.println(ar[0]==1?"2":"1");
			return;
		}
		if (ar[n - 1] == 1) {
			ar[n - 2] = 2;
		}
		System.out.print("1");
		for (int x = 0; x < n - 1; x++) {
			System.out.print(" " + ar[x]);
		}
		System.out.println();
	}
}


/**
 * Created by IntelliJ IDEA.
 * User: mac
 * Date: 11-12-9
 * Time: 下午10:48
 * To change this template use File | Settings | File Templates.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A {

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens())
            tokenizer = new StringTokenizer(reader.readLine());
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = nextInt();
        }
        Arrays.sort(a);
        if (a[a.length - 1] == 1) {
            for (int i = 0; i < a.length - 1; i++) {
                writer.print(1 + " ");
            }
            writer.println(2 + "");
            return;
        }
        for (int i = 0; i < a.length; i++) {
            if (i == 0)
                writer.print(1 + " ");
            else
                writer.print(a[i - 1] + " ");
        }
        writer.println();
    }

    static public void main(String[] args) {
        new A().run();
    }
}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.*;

public class A implements Runnable{

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException{
        if (ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException{
        while(!tok.hasMoreTokens()){
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException{
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException{
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException{
        return Double.parseDouble(readString());
    }

    public static void main(String[] args){
        new Thread(null, new A(), "", 256 * (1L << 20)).start();
    }

    public void run(){
        try{
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = "+(t2-t1));
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    void solve() throws IOException{
        int n = readInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++){
            a[i] = readInt();
        }
        Arrays.sort(a);
        a[n-1] = a[n-1] == 1? 2:1;
        Arrays.sort(a);
        for (int i = 0; i < n; i++){
            out.print(a[i] + " ");
        }
    }
}


import static java.util.Arrays.deepToString;

import java.io.*;
import java.math.*;
import java.util.*;

public class A {

	static int [] solve(int [] a) {
		int n = a.length;
		Arrays.sort(a);
		a[n - 1] = (a[n - 1] > 1 ? 1 : 2);
		int [] b = Arrays.copyOf(a, n);
		Arrays.sort(b);
		return b;
	}

	public static void main(String[] args) throws Exception {
		reader = new BufferedReader(new InputStreamReader(System.in));
		writer = new PrintWriter(System.out);

		setTime();

		int n = nextInt();
		int [] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		int [] b = solve(a);
		for (int v: b) {
			writer.print(v + " ");
		}

		printTime();
		printMemory();

		writer.close();
	}

	static BufferedReader reader;
	static PrintWriter writer;
	static StringTokenizer tok = new StringTokenizer("");
	static long systemTime;

	static void debug(Object... o) {
		System.err.println(deepToString(o));
	}

	static void setTime() {
		systemTime = System.currentTimeMillis();
	}

	static void printTime() {
		System.err.println("Time consumed: " + (System.currentTimeMillis() - systemTime));
	}

	static void printMemory() {
		System.err.println("Memory consumed: "
				+ (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + "kb");
	}

	static String next() {
		while (!tok.hasMoreTokens()) {
			String w = null;
			try {
				w = reader.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (w == null)
				return null;
			tok = new StringTokenizer(w);
		}
		return tok.nextToken();
	}

	static int nextInt() {
		return Integer.parseInt(next());
	}

	static long nextLong() {
		return Long.parseLong(next());
	}

	static double nextDouble() {
		return Double.parseDouble(next());
	}

	static BigInteger nextBigInteger() {
		return new BigInteger(next());
	}
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws Exception {
        int n = nextInt();

        int[] mas = new int[n];

        for(int i = 0; i<n; i++) {
            mas[i] = nextInt();
        }

        Arrays.sort(mas);

        if(mas[n-1] == 1) {
            for(int i = 0; i<n-1; i++) {
                out.print(1 + " ");
            }
            out.println(2);
            out.flush();
            exit();
        }

        out.print("1 ");

        for(int i = 0; i<n-1; i++) {
            out.print(mas[i] + " ");
        }

        out.println();
        out.flush();
    }

    /////////////////////////////////////////////////////////////////
    // IO
    /////////////////////////////////////////////////////////////////
    private static StreamTokenizer in;
    private static PrintWriter out;
    private static BufferedReader inB;

    private static boolean FILE=false;

    private static int nextInt() throws Exception{
        in.nextToken();
        return (int)in.nval;
    }

    private static String nextString() throws Exception{
        in.nextToken();
        return in.sval;
    }

    static{
        try {
            out = new PrintWriter(FILE ? (new FileOutputStream("output.txt")) : System.out);
            inB = new BufferedReader(new InputStreamReader(FILE ? new FileInputStream("input.txt") : System.in));
        } catch(Exception e) {e.printStackTrace();}
        in = new StreamTokenizer(inB);
    }
    /////////////////////////////////////////////////////////////////

    /////////////////////////////////////////////////////////////////
    // pre - written
    /////////////////////////////////////////////////////////////////
    private static void println(Object o) throws Exception {
        out.println(o);
        out.flush();
    }
    private static void exit(Object o) throws Exception {
        println(o);
        exit();
    }
    private static void exit() {
        System.exit(0);
    }
    private static final int  INF = Integer.MAX_VALUE;
    private static final int MINF = Integer.MIN_VALUE;
    //////////////////////////////////////////////////////////////////
}


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

import static java.lang.Math.* ;
import static java.util.Arrays.* ;

public class A {

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

		new A().solveProblem();

		out.close();
	}

	static Scanner in = new Scanner(new InputStreamReader(System.in));
	//static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	static PrintStream out = new PrintStream(new BufferedOutputStream(System.out));

	public void solveProblem() {

		int n = in.nextInt() ;
		E[] get = new E[n] ;
		for( int i = 0 ; i < n ; i++ ){
			get[i] = new E(i,in.nextInt()) ;
		}

		sort(get) ;

		if( get[n-1].g == 1){
			get[n-1].g = 2 ;
		}else{
			get[n-1].g = 1 ;

		}
		sort(get) ;
		for( int i = 0 ; i < n - 1 ; i++ )
			out.print(get[i].g  +" " ) ;
		out.println(get[n-1].g) ;

	}

	class E implements Comparable<E>{
		int g ;
		int index ;

		public E( int index, int g){
			this.g = g ;
			this.index = index ;
		}

		public int compareTo( E e){
			return g - e.g ;
		}
	}

	static int[] readGet( int n ){
	  	int[] get = new int[n] ;
	  	for( int i = 0 ; i < n ; i++ )
	  		get[i] = in.nextInt();
	  	return get ;
	}

}


import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class A_135 {

    /**
     * @param args
     */
    public static void main(String[] args) {

        Scanner in=new Scanner(System.in);

        int n=in.nextInt();

        int[] mas=new int[n];

        for(int i=0;i<n;i++){
            mas[i]=in.nextInt();
        }

        Arrays.sort(mas);

        PrintWriter out=new PrintWriter(System.out);

        boolean isEd=true;
        for(int i=0;i<n;i++)
            if(mas[i]!=1){
                isEd=false;
                break;
            }

        if(!isEd)
            out.print('1');

        for(int i=0;i<n-1;i++){
            out.print(' ');
            out.print(mas[i]);
        }

        if(isEd)
            out.print(" 2");

        out.flush();
    }

}


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

public class CodeForce {

    private void solve() throws IOException {
        final int N = nextInt();
        int []A = new int[N];
        for(int i = 0; i < N; i++) A[i] = nextInt();
        Arrays.sort(A);
        if(A[N-1] == 1) A[N-1] = 2;
        else            A[N-1] = 1;
        Arrays.sort(A);
        for(int i = 0; i < N; i++)
            System.out.print(A[i] + " ");
    }

    public static void main(String[] args) {
        new CodeForce().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(new FileOutputStream(new File("output.txt")));
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return reader.readLine();
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class C {

    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();
        int[] x = new int[n];

        int max=0, pos=-1;
        for(int i=0; i<n; i++) {
            x[i]=sc.nextInt();
            if (max<x[i]) {
                max=x[i];
                pos=i;
            }
        }
        x[pos] = (max==1) ? 2 : 1;

        Arrays.sort(x);

        for(int i=0; i<n; i++)
            System.out.print(x[i]+" ");
    }

}


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

public class TaskA {
	BufferedReader br;
	PrintWriter out;
	StringTokenizer stok;

	String nextToken() throws IOException {
		while (stok == null || !stok.hasMoreTokens()) {
			String s = br.readLine();
			if (s == null) {
				return "-1";
			}
			stok = new StringTokenizer(s);
		}
		return stok.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	char nextChar() throws IOException {
		return (char) (br.read());
	}

	String nextLine() throws IOException {
		return br.readLine();
	}

	void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		Arrays.sort(a);
		a[n - 1] = a[n - 1] == 1 ? 2 : 1;
		Arrays.sort(a);
		for (int i = 0; i < n; i++) {
			out.print(a[i]);
			out.print(' ');
		}
	}

	void run() throws IOException {
		// br = new BufferedReader(new FileReader("taska.in"));
		// out = new PrintWriter("taska.out");
		// br = new BufferedReader(new FileReader("input.txt"));
		// out = new PrintWriter("output.txt");
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		br.close();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		// Locale.setDefault(Locale.US);
		new TaskA().run();
	}
}


import java.io.*;
import java.util.*;
import java.util.prefs.NodeChangeEvent;
import java.math.*;

public class Main implements Runnable {
	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;
	private Random rnd;

	private void solve() throws IOException {
		int n = nextInt();

		int[] a = new int[n];
		int max = 0;
		for(int i = 0; i < n; i++) {
			a[i] = nextInt();
			if(a[i] > a[max]) max = i;
		}

		int value = 1;

		if(a[max] == 1) value = 2;

		a[max] = value;

		Arrays.sort(a);

		for(int i = 0; i < n; i++) {
			out.print(a[i]);
			out.print(' ');
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		try {
			try {
				in = new BufferedReader(new FileReader("INPUT.TXT"));
				out = new PrintWriter(new FileWriter("OUTPUT.TXT"));
			} catch(FileNotFoundException e) {
				in = new BufferedReader(new InputStreamReader((System.in)));
				out = new PrintWriter(System.out);
			}

			st = null;
			rnd = new Random();

			solve();

			out.close();
		} catch(IOException e) {
			e.printStackTrace();
		}
	}

	private String nextToken() throws IOException, NullPointerException {
		while(st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}

		return st.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

}


import java.util.*;
import java.math.*;
public class codeforces {
	 public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] data=new int[n];
		for(int i=0;i<n;i++)
			data[i]=sc.nextInt();
		Arrays.sort(data);
		if(data[n-1]!=1)
			data[n-1]=1;
		else
			data[n-1]=2;
		Arrays.sort(data);
		for(int i=0;i<n;i++)
		{
			System.out.print(data[i]);
			if(i!=n-1)
				System.out.print(" ");
		}

		return;
	}

}


import java.util.*;
public class A {
	static int [] reverse = new int [257];
	public static void main (String [] arg) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int [] A =new int [n];
		for (int i = 0; i<A.length; ++i) A[i] = sc.nextInt();
		Arrays.sort(A);
		if (n == 1) {
			System.out.println( (A[0] == 1) ? "2" : "1");
			return;
		} else if (A[0] == A[A.length-1] && A[0] == 1) {
			System.out.print("1");
			for (int i = 1; i<n-1; ++i) System.out.print(" " + A[i]);
			System.out.println(" 2");
			return;
		} else if (A[0] == A[A.length-1]) {
			System.out.print("1");
			for (int i = 1; i<n; ++i) System.out.print(" " + A[i]);
			System.out.println();
			return;
		}

		for (int i = 0; i<A.length; ++i) {
			int prev = (i == 0) ? Integer.MAX_VALUE : A[i-1];
			int next = (i == A.length-1) ? Integer.MAX_VALUE : A[i+1];
			int ans = Math.min(prev, Math.min(next, A[i]));
			if (i == 0) ans = 1;

			System.out.print((i == 0) ? "" + ans : " " + ans);
		}
		System.out.println();

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class C {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        String[] S = in.readLine().split(" ");
        int[] A = new int[n];
        boolean allOnes = true;
        for (int i = 0; i < n; i++) {
            A[i] = Integer.parseInt(S[i]);
            allOnes &= A[i] == 1;
        }
        Arrays.sort(A);
        if (A[A.length - 1] > 1)
            A[A.length - 1] = 1;
        else
            A[A.length - 1] = 2;
        Arrays.sort(A);
        for (int i = 0; i < A.length; i++)
            System.out.print(A[i] + " ");
        System.out.println();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class C implements Runnable {

	private void Solution() throws IOException {
		int n = nextInt(), max = 0, maxi = 0;
		ArrayList<Integer> mas = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			int num = nextInt();
			if (num > max) {
				max = num;
				maxi = i;
			}
			mas.add(num);
		}
		mas.remove(maxi);
		mas.add(max == 1 ? 2 : 1);
		Collections.shuffle(mas);
		Collections.sort(mas);
		for (int i = 0; i < n; i++)
			System.out.print(mas.get(i) + " ");
	}

	public static void main(String[] args) {
		new C().run();
	}

	BufferedReader in;
	StringTokenizer tokenizer;

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			Solution();
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(in.readLine());
		return tokenizer.nextToken();
	}
}


import java.io.*;
import java.math.*;
import java.util.*;

public class Main
{
    BufferedReader reader;
    FastScanner sc;

    void solve() throws Exception
    {
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        if (arr[n - 1] == 1)
            arr[n - 1] = 2;
        else
            arr[n - 1] = 1;
        Arrays.sort(arr);
        for (int i = 0; i < n; i++)
        {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) throws Exception
    {
        new Main().solve();
    }

    Main() throws Exception
    {
        if (System.getProperty("ONLINE_JUDGE") == null)
        {
            //System.setIn(new FileInputStream("input.txt"));
            //System.setOut(new PrintStream("output.txt"));
        }

        reader = new BufferedReader(new InputStreamReader(System.in));
        sc = new FastScanner(reader);
    }
}

class FastScanner
{
    BufferedReader reader;
    StringTokenizer strTok;

    public FastScanner(BufferedReader reader)
    {
        this.reader = reader;
    }

    public String nextToken() throws IOException
    {
        if (strTok == null || !strTok.hasMoreTokens())
        {
            strTok = new StringTokenizer(reader.readLine());
        }
        return strTok.nextToken();
    }

    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException
    {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextToken());
    }

    public BigInteger nextBigInteger() throws IOException
    {
        return new BigInteger(nextToken());
    }

    public BigDecimal nextBigDecimal() throws IOException
    {
        return new BigDecimal(nextToken());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class C {
	BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer st = null;

	private void solution() throws IOException {
		int n = nextInt();
		int[] mas = new int[n];
		for (int i = 0; i < n; i++) {
			mas[i] = nextInt();
		}

		Arrays.sort(mas);

		if (mas[n - 1] == 1) {
			mas[n - 1] = 2;
		} else {
			mas[n - 1] = 1;
		}
		Arrays.sort(mas);
		for (int i = 0; i < n; i++) {
			System.out.print(mas[i] + " ");
		}

	}

	String nextToken() throws IOException {
		if (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(bf.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public static void main(String args[]) throws IOException {
		new C().solution();
	}
}


import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.regex.*;
import static java.lang.Math.*;
public class A {

    public A() throws Exception {
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i=0;i<n;i++)
            arr[i] = in.nextInt();

        if (n==1&&arr[0]==1) {
            System.out.println(2);
            return;
        }

        Arrays.sort(arr);
        if (arr[n-1]==1)
            arr[n-2] = 2;
        buf.append(1);
        for (int i=0;i<n-1;i++)
            buf.append(' ').append(arr[i]);
        buf.append('\n');
        System.out.print(buf);
    }

    Scanner in = new Scanner(System.in);
    StringBuilder buf = new StringBuilder();
    public static void main(String[] args) throws Exception { // {{{
        new A();
    } // }}}
    public static void debug(Object... arr) { // {{{
        System.err.println(Arrays.deepToString(arr));
    } // }}}
}


import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.AbstractList;
import java.io.Writer;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int size = in.readInt();
		int[] array = IOUtils.readIntArray(in, size);
		Arrays.sort(array);
		if (array[size - 1] == 1)
			array[size - 1] = 2;
		else
			array[size - 1] = 1;
		Arrays.sort(array);
		out.printLine(Array.wrap(array).toArray());
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(outputStream);
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

class IOUtils {

	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}

	}

abstract class Array<T> extends AbstractList<T> {

	public static List<Integer> wrap(int...array) {
		return new IntArray(array);
	}

	protected static class IntArray extends Array<Integer> {
		protected final int[] array;

		protected IntArray(int[] array) {
			this.array = array;
		}

		public int size() {
			return array.length;
		}

		public Integer get(int index) {
			return array[index];
		}

		public Integer set(int index, Integer value) {
			int result = array[index];
			array[index] = value;
			return result;
		}
	}

	}


import java.io.*;
import java.math.*;
import java.util.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

	public void solve() throws Exception {
		int n = nextInt();
		int a [] = new int [n];
		for (int i = 0 ;i < n; i++) {
			a[i] = nextInt();
		}
		Arrays.sort(a);
		if (n == 1) {
			if (a[0] == 1) {
				out.print(2);
			} else {
				out.print(1);
			}
		} else {
			out.print(1);
			for (int i = 1; i < n; i++) {
				if (i == n-1 && a[i] == 1) {
					out.print(" "+2);
				} else {
					out.print(" "+a[i-1]);
				}
			}
		}
	}

	/********************************************************************************************/
	/* THERE IS INPUT */

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	long stime=0;

	private String next() throws Exception {
		while (st == null || !st.hasMoreElements())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	private int nextInt() throws Exception {
		return Integer.parseInt(next());
	}

	private long nextLong() throws Exception {
		return Long.parseLong(next());
	}

	private double nextDouble() throws Exception {
		return Double.parseDouble(next());
	}

	public void run() {
		try {
			//Locale.setDefault(Locale.US);
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
			solve();
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Exception {
		new Thread(null, new Solution(), "", 1 << 25).start();
	}

}


import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int[] a = new int[n];
        boolean has_more_than_one = false;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            if (a[i] > 1)
                has_more_than_one = true;
        }

        Arrays.sort(a);

        if (n == 1) {
            if (a[0] == 1)
                out.print(2);
            else
                out.print(1);
        } else {
            out.print(1 + " ");
            for (int i = 1; i < n; i++) {
                if (has_more_than_one || i < n - 1)
                    out.print(a[i - 1] + " ");
                else
                    out.println(2);
            }
        }

        out.close();
    }
}


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

public class A implements Runnable {
    private MyScanner in;
    private PrintWriter out;

    private void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        int max = -1, maxp = -1;
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
            if (a[i] > max) {
                max = a[i];
                maxp = i;
            }
        }
        if (max == 1) {
            for (int i = 0; i < n - 1; ++i) {
                out.print(1 + " ");
            }
            out.println(2);
            return;
        }
        a[maxp] = 1;
        Arrays.sort(a);
        for (int i = 0; i < n; ++i) {
            out.print(a[i] + " ");
        }
        out.println();
    }

    @Override
    public void run() {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    public static void main(String[] args) {
        new A().run();
    }

    static class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        private String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
            return st.nextToken();
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        public String next() {
            return nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


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

public class A implements Runnable{

    public void run() {
        int n = nextInt();
        int[] arr = new int[n];
        boolean allOne = true;
        for (int i = 0; i < n; ++i) {
            arr[i] = nextInt();
            if (arr[i] != 1) {
                allOne = false;
            }
        }
        Arrays.sort(arr);
        if (!allOne) {
            out.print("1 ");
        }
        for (int i = 0; i < n-1; ++i) {
            out.print(arr[i] + " ");
        }
        if (allOne) {
            out.print("2");
        }
        out.println();
        out.flush();
    }

    private static BufferedReader br = null;
    private static PrintWriter out = null;
    private static StringTokenizer stk = null;

    public static void main(String[] args) {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        (new Thread(new A())).start();
    }

    private void loadLine() {
        try {
            stk = new StringTokenizer(br.readLine());
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    private String nextLine() {
        try {
            return br.readLine();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    private Integer nextInt() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Integer.parseInt(stk.nextToken());
    }

    private Long nextLong() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Long.parseLong(stk.nextToken());
    }

    private String nextWord() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return (stk.nextToken());
    }

    private Double nextDouble() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Double.parseDouble(stk.nextToken());
    }

}


import java.util.Arrays;
import java.util.Scanner;

public class AAA {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = in.nextInt();
        int max = a[0];
        int ind = 0;
        for (int k = 1; k < n; k++) {
            if (a[k] > max) {
                max = a[k];
                ind = k;
            }
        }
        if (max != 1) {
            a[ind] = 1;
            Arrays.sort(a);
            for (int i = 0; i < a.length - 1; i++)
                System.out.print(a[i] + " ");
            System.out.println(a[a.length - 1]);
        } else {
            a[0] = 2;
            Arrays.sort(a);
            for (int i = 0; i < a.length - 1; i++)
                System.out.print(a[i] + " ");
            System.out.println(a[a.length - 1]);
        }
    }
}


import java.util.*;
public class A135 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        Arrays.sort(arr);
        int[] ans = new int[n];

        if (arr[n-1] == 1) {
            for (int i = 0 ;i < n; i++) {
                ans[i] = arr[i];
            }
            ans[n-1] = 2;
        } else {
            ans[0] = 1;
            for (int i = 1; i < n; i++) {
                ans[i] = arr[i-1];
            }
        }
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < n; i++) {
            buf.append(ans[i]);
            if (i != n-1) buf.append(' ');
        }
        System.out.print(buf.toString());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(r.readLine());

        String[] line = r.readLine().split("[ ]+");

        int[] a = new int[n];
        for(int i = 0; i < n; i++)
            a[i] = Integer.parseInt(line[i]);

        Arrays.sort(a);

        boolean found = false;
        for(int i = 0; i < n && !found; i++)
            if(a[i] != 1)found = true;

        if(found){
            System.out.println(1);
            for(int i = 1; i < n; i++)
                System.out.println(a[i-1]);
        }else{
            for(int i = 0; i < n-1; i++)
                System.out.println(1);
            System.out.println(2);
        }
    }
}


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

public class A {

    BufferedReader in;
    StringTokenizer st;
    PrintWriter out;

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }

    int nextInt() throws Exception {
        return Integer.parseInt(next());
    }

    long nextLong() throws Exception {
        return Long.parseLong(next());
    }

    double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }

    void solve() throws Exception {
        // int min = 1;
        // int max = 1000000000;
        int n = nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();

        Arrays.sort(a);

        if (a[n - 1] == 1) {
            for (int i = 1; i < n; i++)
                out.print("1 ");
            out.print(2);
            return;
        }

        // a[0]=max;

        Arrays.sort(a);
        out.print(1);
        for (int i = 1; i < n; i++)
            out.print(" " + a[i-1]);

    }

    void run() {
        try {
            Locale.setDefault(Locale.US);
            boolean oj = System.getProperty("ONLINE_JUDGE") != null;
            Reader reader = oj ? new InputStreamReader(System.in)
                    : new FileReader("input.txt");
            Writer writer = oj ? new OutputStreamWriter(System.out)
                    : new FileWriter("output.txt");
            in = new BufferedReader(reader);
            out = new PrintWriter(writer);

            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public static void main(String[] args) {
        new A().run();

    }

}


import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Scanner;

public class Beta97B {

    static Scanner in;
    static StreamTokenizer st;
    static int n;
    static int[] a;
    static int max = 1;

    public static void main(String[] args) throws IOException {
        // in = new Scanner(System.in);
        st = new StreamTokenizer(new InputStreamReader(System.in));
        n = nextInt();
        a = new int[n];
        int ind = 0;
        for (int i = 0; i < n; ++i) {
            a[i] = nextInt();
            if (a[i] > max) {
                max = a[i];
                ind = i;
            }
        }
        if (max == 1) {
            a[0] = 2;
        } else {
            a[ind] = 1;
        }
        Arrays.sort(a);
        for (int i = 0; i < n; ++i)
            System.out.print(a[i] + " ");
    }

    private static int nextInt() throws IOException {
        st.nextToken();
        return (int) st.nval;
    }
}


//package round97;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A {

	static BufferedReader bf = new BufferedReader(new InputStreamReader(
			System.in));
	static StringTokenizer st;
	static PrintWriter out = new PrintWriter(System.out);

	static String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String s = bf.readLine();
			if (s == null)
				return null;
			st = new StringTokenizer(s);
		}

		return st.nextToken();
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static String nextStr() throws IOException {
		return nextToken();
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public static void main(String[] args) throws IOException {
		int n = nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		Arrays.sort(a);

		for (int q = 0; q < n; q++) {
			if (a[q] != 1) {
				out.print("1");
				for (int i = 1; i < n; i++) {
					out.print(" " + a[i - 1]);
				}
				out.flush();
				return;
			}
		}

		for (int i = 0; i < n - 1; i++) {
			out.print("1 ");
		}
		out.println("2");
		out.flush();

	}
}


import java.util.Arrays;
import java.util.Scanner;

public class A {

    void run(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        boolean dif = false;
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        Arrays.sort(a);
        if(n==1){
            System.out.println(a[0]==1?2:1);return;
        }
        int[] m = new int[n];
        for(int i=1;i<n;i++)if(a[i]!=a[i-1])dif=true;
        m[0] = 1;
        for(int i=1;i<n;i++)m[i]=a[i-1];
        if(!dif&&a[0]==1)m[n-1]++;

        for(int i=0;i<n;i++)System.out.print(m[i]+(i==n-1?"\n":" "));
    }

    public static void main(String[] args) {
        new A().run();
    }
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class ProblemA {

	private void solve() throws IOException {
		Scanner stdin = new Scanner(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = Integer.valueOf(stdin.nextInt());
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
        	p[i] = stdin.nextInt();
        }

        Arrays.sort(p);
        if (p[n-1] == 1) {
        	p[n-1] = 2;
        } else {
        	p[n-1] = 1;
        	out.print(p[n-1] + " ");
        	n--;
        }

        for (int i = 0; i < n; i++) {
        	out.print(p[i] + " ");
        }

        out.flush();
        out.close();
	}

	public static void main(String[] args) throws IOException {
		ProblemA solver = new ProblemA();
        solver.solve();
	}
}


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

public class A{
    public static void main(String[] args) throws Exception{
        new A().run();
    }

    void run() throws Exception{
        //Scanner sc = new Scanner(System.in);
        BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(sc.readLine());
        ArrayList<Integer> a = new ArrayList<Integer>();
        //a.add(1);
        StringTokenizer st = new StringTokenizer(sc.readLine(), " ");
        boolean allOne = true;
        for(int i = 0; i < n; i++){
            int val = Integer.parseInt(st.nextToken());
            if(val!=1)allOne = false;
            a.add(val);
        }
        if(allOne){a.remove(n-1); a.add(2);}
        else a.add(1);
        Collections.sort(a);
        System.out.print(a.get(0));
        for(int i = 1; i < n; i++)
            System.out.print(" " + a.get(i));
        System.out.println();
    }
}


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

public class A {

	final String filename = new String("A").toLowerCase();

	void solve() throws Exception {
		int n = nextInt();
		int[] a = new int[n];
		int m = -1;
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
			if (m == -1 || a[i] > a[m]) {
				m = i;
			}
		}
		if (a[m] == 1)
			a[m] = 2;
		else
			a[m] = 1;
		Arrays.sort(a);
		for (int i = 0; i < n; i++) {
			out.print(a[i] + " ");
		}

	}

	void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			// in = new BufferedReader(new FileReader("input.txt"));
			// out = new PrintWriter("output.txt");

			solve();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

	String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

	public static void main(String[] args) {
		new A().run();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ProblemA {

    private final BufferedReader in;
    private final PrintStream out;
    private StringTokenizer tok = new StringTokenizer("");
    private String nextLine = null;

    public static void main(String[] args) throws Exception {
        new ProblemA();
    }

    private ProblemA() throws Exception {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = System.out;
        start();
        end();
    }

    private int nextInt() {
        return Integer.parseInt(nextWord());
    }

    private String nextWord() {
        if (tok.hasMoreTokens()) {
            return tok.nextToken();
        } else {
            while (!tok.hasMoreTokens()) {
                try {
                    nextLine = in.readLine();
                    if (nextLine == null) {
                        return null;
                    } else {
                        tok = new StringTokenizer(nextLine);
                    }
                } catch (IOException ex) {
                    Logger.getLogger(ProblemA.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            return tok.nextToken();
        }
    }

    private void start() {
        int n = nextInt();
        int[] a = new int[n];
        boolean allOne = true;
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
            if (a[i] != 1) {
                allOne = false;
            }
        }
        Arrays.sort(a);
        int[] res = new int[n];
        res[0] = 1;
        for (int i = 1; i < n; i++) {
            res[i] = a[i - 1];
        }
        if (allOne) {
            for (int i = 0; i < n - 1; i++) {
                out.print(a[i] + " ");
            }
            out.print(2);
        } else {
            for (int i = 0; i < n; i++) {
                out.print(res[i] + " ");
            }
        }
    }

    private void end() {
        out.close();
    }
}


import java.util.*;

public class Main {

  public static void main(String args[]) {
    (new Main()).solve();
  }

  void solve() {

    Scanner cin = new Scanner(System.in);

    while( cin.hasNextInt() ) {

      int n = cin.nextInt();
      int arr[] = new int[n];
      for(int i=0; i<n; ++i) {
        arr[i] = cin.nextInt();
      }

      Arrays.sort(arr);

      int ret[] = new int[n];
      ret[0] = 1;
      for(int i=0; i<n-1; ++i) { ret[i + 1] = arr[i]; }
      if( arr[n - 1] == 1 ) { ret[n - 1] = 2; }

      String glue = "";
      for(int i=0; i<n; ++i) {
        System.out.print(glue + ret[i]);
        glue = " ";
      }

      System.out.println();

    }

  }

}


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

public class Solution implements Runnable{
    public static BufferedReader br;
    public static PrintWriter out;
    public static StringTokenizer stk;
    public static boolean isStream = true;

    public static void main(String[] args) throws IOException {
    	if (isStream) {
            br = new BufferedReader(new InputStreamReader(System.in));
        } else {
            br = new BufferedReader(new FileReader("in.txt"));
        }
        out = new PrintWriter(System.out);
        new Thread(new Solution()).start();
    }

    public void loadLine() {
        try {
            stk = new StringTokenizer(br.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public String nextLine() {
        try {
            return br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

    public String nextWord() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return stk.nextToken();
    }

    public Integer nextInt() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Integer.valueOf(stk.nextToken());
    }

    public Long nextLong() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Long.valueOf(stk.nextToken());
    }

    public Double nextDouble() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Double.valueOf(stk.nextToken());
    }

    public Float nextFloat() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Float.valueOf(stk.nextToken());
    }

    public void run() {
    	int n = nextInt();
    	int[] arr = new int[n];
    	for (int i = 0; i < n;i++) {
    		arr[i] = nextInt();
    	}
    	Arrays.sort(arr);
    	if (arr[n-1] != 1) arr[n-1] = 1;
    	else arr[n-1] = 2;
    	Arrays.sort(arr);
    	for (int i = 0; i < n; i++) {
    		out.print(arr[i]+" ");
    	}
    	out.println();
    	out.flush();
    }
}


//package round97;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;

public class A {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = ni();
		}
		Arrays.sort(a);
		if(a[n-1] > 1){
			a[n-1] = 1;
			Arrays.sort(a);
		}else{
			a[n-1] = 2;
		}
		for(int i = 0;i < n;i++){
			if(i > 0)out.print(" ");
			out.print(a[i]);
		}
		out.println();
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception
	{
		new A().run();
	}

	public int ni()
	{
		try {
			int num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public long nl()
	{
		try {
			long num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public String ns()
	{
		try{
			int b = 0;
			StringBuilder sb = new StringBuilder();
			while((b = is.read()) != -1 && (b == '\r' || b == '\n' || b == ' '));
			if(b == -1)return "";
			sb.append((char)b);
			while(true){
				b = is.read();
				if(b == -1)return sb.toString();
				if(b == '\r' || b == '\n' || b == ' ')return sb.toString();
				sb.append((char)b);
			}
		} catch (IOException e) {
		}
		return "";
	}

	public char[] ns(int n)
	{
		char[] buf = new char[n];
		try{
			int b = 0, p = 0;
			while((b = is.read()) != -1 && (b == ' ' || b == '\r' || b == '\n'));
			if(b == -1)return null;
			buf[p++] = (char)b;
			while(p < n){
				b = is.read();
				if(b == -1 || b == ' ' || b == '\r' || b == '\n')break;
				buf[p++] = (char)b;
			}
			return Arrays.copyOf(buf, p);
		} catch (IOException e) {
		}
		return null;
	}

	double nd() { return Double.parseDouble(ns()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class C {

        final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;
        BufferedReader in;
        PrintWriter out;
        StringTokenizer tok = new StringTokenizer("");

        void init() throws FileNotFoundException{
                if (ONLINE_JUDGE){
                        in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
                }else{
                        in = new BufferedReader(new FileReader("input.txt"));
                        out = new PrintWriter("output.txt");
                }
        }

        String readString() throws IOException{
                while(!tok.hasMoreTokens()){
                        tok = new StringTokenizer(in.readLine());
                }
                return tok.nextToken();
        }

        int readInt() throws IOException{
                return Integer.parseInt(readString());
        }

        long readLong() throws IOException{
                return Long.parseLong(readString());
        }

        double readDouble() throws IOException{
                return Double.parseDouble(readString());
        }

        public static void main(String[] args){
                new C().run();
        }

        public void run(){
                try{
                        long t1 = System.currentTimeMillis();
                        init();
                        solve();
                        out.close();
                        long t2 = System.currentTimeMillis();
                        System.err.println("Time = "+(t2-t1));
                }catch (Exception e){
                        e.printStackTrace(System.err);
                        System.exit(-1);
                }
        }

        void solve() throws IOException{
        	int n = readInt();
        	int[] a = new int[n];
        	for(int i = 0; i < n; i++){
        		a[i] = readInt();
        	}
        	boolean c = true;
        	for(int i = 0; i < n; i++){
        		if(a[i] != 1){
        			c = false;
        			break;
        		}
        	}
        	if(c){
        		for(int i = 0; i < n-1; i++){
        			out.print(a[i] + " ");
        		}
        		out.println(2);
        		return;
        	}
        	Utils.mergeSort(a);
        	out.print(1 + " ");
        	for(int i = 1; i < n; i++){
        		out.print(a[i-1] + " ");
        	}
        }

        int[] zFunction(char[] s){
        	int[] z = new int[s.length];
        	z[0] = 0;
        	for (int i=1, l=0, r=0; i<s.length; ++i) {
        		if (i <= r)
        			z[i] = min (r-i+1, z[i-l]);
        		while (i+z[i] < s.length && s[z[i]] == s[i+z[i]])
        			++z[i];
        		if (i+z[i]-1 > r){
        			l = i;
        			r = i+z[i]-1;
        		}
        	}
        	return z;
        }

        int[] prefixFunction(char[] s){
        	int[] pr = new int[s.length];
        	for (int i = 1; i< s.length; ++i) {
        		int j = pr[i-1];
        		while (j > 0 && s[i] != s[j])
        			j = pr[j-1];
        		if (s[i] == s[j])  ++j;
        		pr[i] = j;
        	}
        	return pr;
        }

        int ModExp(int a, int n, int mod){
        	int res = 1;
        	while (n!=0)
        		if ((n & 1) != 0) {
        			res = (res*a)%mod;
        			--n;
        		}
        		else {
        			a = (a*a)%mod;
        			n >>= 1;
        		}
        	return res;
        }

        static class Utils {

                private Utils() {}

                public static void mergeSort(int[] a) {
                        mergeSort(a, 0, a.length - 1);
                }

                private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
                        final int MAGIC_VALUE = 50;
                        if (leftIndex < rightIndex) {
                                if (rightIndex - leftIndex <= MAGIC_VALUE) {
                                        insertionSort(a, leftIndex, rightIndex);
                                } else {
                                        int middleIndex = (leftIndex + rightIndex) / 2;
                                        mergeSort(a, leftIndex, middleIndex);
                                        mergeSort(a, middleIndex + 1, rightIndex);
                                        merge(a, leftIndex, middleIndex, rightIndex);
                                }
                        }
                }

                private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
                        int length1 = middleIndex - leftIndex + 1;
                        int length2 = rightIndex - middleIndex;
                        int[] leftArray = new int[length1];
                        int[] rightArray = new int[length2];
                        System.arraycopy(a, leftIndex, leftArray, 0, length1);
                        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
                        for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
                                if (i == length1) {
                                        a[k] = rightArray[j++];
                                } else if (j == length2) {
                                        a[k] = leftArray[i++];
                                } else {
                                        a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
                                }
                        }
                }

                private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
                        for (int i = leftIndex + 1; i <= rightIndex; i++) {
                                int current = a[i];
                                int j = i - 1;
                                while (j >= leftIndex && a[j] > current) {
                                        a[j + 1] = a[j];
                                        j--;
                                }
                                a[j + 1] = current;
                        }
                }
        }

        boolean isPrime(int a){
        	for(int i = 2; i <= sqrt(a); i++)
        		if(a % i == 0) return false;
        	return true;
        }

        static double distance(long x1, long y1, long x2, long y2){
        	return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        }

        static long gcd(long a, long b){
        	if(min(a,b) == 0) return max(a,b);
        	return gcd(max(a, b) % min(a,b), min(a,b));
        }

        static long lcm(long a, long b){
        	return a * b /gcd(a, b);
        }
}


import java.util.Arrays;
import java.util.Scanner;

public class A {
    static final Scanner sc = new Scanner(System.in);

    void run() {
        int n = sc.nextInt();
        int[] xs = new int[n];
        for(int i = 0; i < n; i++) {
            xs[i] = sc.nextInt();
        }
        Arrays.sort(xs);
        xs[n-1] = xs[n-1] == 1 ? 2 : 1;
        Arrays.sort(xs);
        for(int i = 0; i < n; i++)
            System.out.print(xs[i] + " ");
    }

    public static void main(String[] args) {
        new A().run();
    }
}


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

public class Replacement {
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		String s=r.readLine();
		int n=new Integer(s);
		int[]arr=new int[n];
		String[]sp=r.readLine().split("[ ]+");
		for (int i = 0; i < sp.length; i++) {
			arr[i]=new Integer(sp[i]);
		}
		Arrays.sort(arr);
		if(arr[arr.length-1]==1){
			arr[arr.length-1]=2;
			Arrays.sort(arr);
			for (int i = 0; i < n; i++) {
				if(i==n-1){
					System.out.println(arr[i]);
				}else
				System.out.print(arr[i]+" ");
			}
			return;
		}
		arr[arr.length-1]=1;
		Arrays.sort(arr);
		for (int i = 0; i < n; i++) {
			if(i==n-1){
				System.out.println(arr[i]);
			}else
			System.out.print(arr[i]+" ");
		}
	}
}


import java.io.*;

import java.awt.geom.Point2D;
import java.text.*;
import java.math.*;
import java.util.*;

public class Main implements Runnable {

	final String filename = "";

	public void solve() throws Exception {
		int n = iread();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = iread();
		Arrays.sort(a);
		boolean test = true;

		for (int i = 0; i < n; i++) {
			if (a[i] != 1)
				test = false;
			int min = (i == 0) ? 1 : a[i - 1];
			if (test && i == n - 1)
				out.write((min + 1) + "");
			else
				out.write(min + "");
			if (i == n - 1)
				out.write("\n");
			else
				out.write(" ");
		}
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));
			// in = new BufferedReader(new FileReader(filename+".in"));
			// out = new BufferedWriter(new FileWriter(filename+".out"));
			solve();
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public int iread() throws Exception {
		return Integer.parseInt(readword());
	}

	public double dread() throws Exception {
		return Double.parseDouble(readword());
	}

	public long lread() throws Exception {
		return Long.parseLong(readword());
	}

	BufferedReader in;

	BufferedWriter out;

	public String readword() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) {
		try {
			Locale.setDefault(Locale.US);
		} catch (Exception e) {

		}
		// new Thread(new Main()).start();
		new Thread(null, new Main(), "1", 1 << 25).start();
	}
}


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

public class A {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;

    void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];

        boolean onlyOnes = true;

        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
            if (a[i] != 1)
                onlyOnes = false;
        }

        Arrays.sort(a);
        if (onlyOnes) {
            for (int i = 0; i < n - 1; i++)
                out.print("1 ");
            out.print(2);
        } else {
            out.print("1 ");
            for (int i = 0; i < n - 1; i++)
                out.print(a[i] + " ");
        }

    }

    void inp() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new A().inp();
    }

    String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return "0";
            }
        }
        return st.nextToken();
    }

    String nextString() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return "0";
            }
        }
        return st.nextToken("\n");
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

}


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

/*
 * Raudel Ravelo Suarez
 * Problem:
 */

public class C
{
	Scanner sc;
	BufferedReader in;
	PrintStream out;
	StringTokenizer tok;

	public C() throws NumberFormatException, IOException
	{
		//sc = new Scanner(System.in);
		//sc = new Scanner(new FileReader("in.txt"));
		in = new BufferedReader(new InputStreamReader(System.in));
		//in = new BufferedReader(new FileReader("in.txt"));
		out = System.out;
		run();
	}
	void run() throws NumberFormatException, IOException
	{
		//Add your code here
		int[] array;
		int n = nextInt();
		array = new int[n];
		int max = 0;
		int pos = 0;
		for(int i = 0; i <n; i++)
		{
			int l = nextInt();
			if(l > max)
			{
				pos = i;
				max = l;
			}
			array[i] = l;
		}
		if(max == 1)array[pos] = 2;
		else array [pos] = 1;
		Arrays.sort(array);
		out.print(array[0]);
		for(int i = 1; i < n; i++)
			out.print(" " + array[i]);
		out.println();
	}
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		new C();
	}
	String nextToken() throws IOException
	{
		if(tok ==null || !tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine());
		return tok.nextToken();
	}
	int nextInt() throws NumberFormatException, IOException
	{
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws NumberFormatException, IOException
	{
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws NumberFormatException, IOException
	{
		return Double.parseDouble(nextToken());
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.StringTokenizer;

public class c {
	public static void main(String[] args) throws IOException {
		FastScanner in = new FastScanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		long bounty = in.nextInt(), increase = in.nextInt();
		int damage = in.nextInt();
		int[] mh = new int[n];
		int[] sh = new int[n];
		int[] reg = new int[n];
		long countKilled = 0;
		ArrayList<Event> es = new ArrayList<>();
		Event[] regen = new Event[n];
		for(int i=0;i<n;i++) {
			mh[i] = in.nextInt();
			sh[i] = in.nextInt();
			reg[i] = in.nextInt();
			if(sh[i] <= damage)
				countKilled++;
			if(reg[i] > 0) {
				int time = (damage+1 - sh[i]+reg[i]-1)/reg[i];
				if(time > 0 && mh[i] >= damage+1) {
					Event e2 = new Event(time, i, damage+1);
					regen[i] = e2;
					es.add(e2);
				}
			}
		}
		for(int i=0;i<m;i++) {
			Event e = new Event(in.nextInt(), in.nextInt()-1, in.nextInt());
			es.add(e);
			if(reg[e.e] > 0) {
				int time = (damage+1 - e.h+reg[e.e]-1)/reg[e.e];
				if(time > 0 && mh[e.e] >= damage+1) {
					Event e2 = new Event(e.t + time, e.e, damage+1);
					e.regen = e2;
					es.add(e2);
				}
			}
		}
		Collections.sort(es, (a,b) -> a.t-b.t);
		long ans = countKilled*bounty;
		int lastTime = 0;
		for(Event e : es) {
			if(e.t == -1) continue;
			if(regen[e.e] != e && regen[e.e] != null) {
				regen[e.e].t = -1;
				regen[e.e] = null;
			}
			if(lastTime != e.t) {
				ans = Math.max(ans, countKilled*(bounty+(e.t-1)*increase));
			}
			if(sh[e.e] <= damage)
				countKilled--;
			sh[e.e] = e.h;
			if(sh[e.e] <= damage)
				countKilled++;
			if(e.regen != null) {
				regen[e.e] = e.regen;
			}
			lastTime = e.t;
		}
		if(countKilled != 0) {
			if(increase > 0)
				ans = -1;
			else
				ans = Math.max(ans, countKilled*bounty);
		}
		System.out.println(ans);
	}
	static class Event {
		int t;
		int e;
		int h;
		Event regen;
		public Event(int tt, int ee, int hh) {
			t = tt;
			e = ee;
			h = hh;
		}
	}
	static class FastScanner {
	    BufferedReader br;
	    StringTokenizer st;
	    public FastScanner(InputStream i) {
	        br = new BufferedReader(new InputStreamReader(i));
	        st = new StringTokenizer("");
	    }
	    public String next() throws IOException {
	        if(st.hasMoreTokens())
	            return st.nextToken();
	        else
	            st = new StringTokenizer(br.readLine());
	        return next();
	    }
	    public int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }
	    public long nextLong() throws IOException {
	        return Long.parseLong(next());
	    }
	    public double nextDouble() throws IOException {
	        return Double.parseDouble(next());
	    }
	}
}