#include <iostream>
#include <vector>
#include <algorithm>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::sort;
int main() {
int N;
int num;
vector<int> vec;
while (cin >> N) {
if (N == 1) {
cin >> num;
cout << num << endl << -1 << endl;
continue;
}
for (int i = 0; i < N; i++) {
cin >> num;
vec.push_back(num);
}
// 遍历一次,找到最大数
vector<int>::iterator it;
vector<int>::iterator Max = vec.begin();
for (it = vec.begin(); it != vec.end(); it++) {
if (*it > *Max)
Max = it;
}
cout << *Max << endl;
vec.erase(Max); // 删除最大数
sort(vec.begin(), vec.end());
for (auto elem : vec)
cout << elem << ' ';
cout << endl;
vec.clear(); // 清空数据,进入下次循环
}
return 0;
}