// Arup Guha
// 1/23/2015
// Solution to 2013 MCPC Problem F: Digit Sum

import java.util.*;

public class f {

	final public static int MAX = 9;

	public static void main(String[] args) {

		// Store powers of 10.
		int[] pow10 = new int[MAX];
		pow10[0] = 1;
		for (int i=1; i<MAX; i++)
			pow10[i] = pow10[i-1]*10;

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();

		while (n != 0) {

			// Read in digits.
			ArrayList<Integer> nonzero = new ArrayList<Integer>();
			int zerocount = 0;
			for (int i=0; i<n; i++) {
				int digit = stdin.nextInt();
				if (digit > 0) nonzero.add(digit);
				else		   zerocount++;
			}

			// Need to be sorted.
			Collections.sort(nonzero);

			// First add in two most significant digits.
			int res = nonzero.get(0)*pow10[(n-1)/2] + nonzero.get(1)*pow10[(n-2)/2];

			// Go backwards (largest to smallest) through rest...
			// greedily using from least significant digit up.
			int used = 0;
			for (int i=nonzero.size()-1; i>=2; i--) {
				res += (nonzero.get(i)*pow10[used/2]);
				used++;
			}

			// ta da!
			System.out.println(res);

			// Get next case.
			n = stdin.nextInt();
		}
	}
}