#include<bits/stdc++.h
using namespace std; const long long ALPHABET_SIZE = 3; // trie node struct TrieNode{ TrieNode *children[ALPHABET_SIZE]; bool isEndOfWord; }; TrieNode *getNode(void){ 	TrieNode *pNode = new TrieNode; 	pNode->isEndOfWord = false; 	long long i; 	for (i = 0; i < ALPHABET_SIZE; i++){ 		pNode->children[i] = NULL; 	} 	return pNode; } void insert(TrieNode *root, string key){ 	TrieNode *pCrawl = root; 	long long i; 	for (i = 0; i < key.length(); i++){ 		long long index = key[i] - 'a'; 		if (!pCrawl->children[index]){ 			pCrawl->children[index] = getNode(); 		} 		pCrawl = pCrawl->children[index]; 	} 	pCrawl->isEndOfWord = true; } bool flag=false; void search(TrieNode *root, string key,long long cnt,long long j){ 	long long i; 	if(root==NULL){ 		return; 	} 	if(j==key.size()){ if(root->isEndOfWord && cnt<=1){ 		flag=true; }		return;  }	for(i=0;i<3 && !flag;i++){ 		if(key[j]==('a'+i)){ 			search(root->children[i],key,cnt,j+1); 		} 		else if(cnt==0){ 			search(root->children[i],key,cnt+1,j+1); 		} 	} } int main(){ 	ios_base::sync_with_stdio(false); 	cin.tie(0); 	cout.tie(0); 	long long n,m,i,j; 	string s; 	cin>>n>>m; 	TrieNode *root = getNode(); 	for(i=0;i<n;i++){ 		cin>>s; 		insert(root,s); 	} 	for(i=0;i<m;i++){ 		cin>>s; 		flag=false; 		TrieNode *p=root; 		search(p,s,0LL,0LL); 		(flag)?cout<<"YES\n":cout<<"NO\n"; 		//search(root,s)?cout<<"YES\n":cout<<"NO\n"; 	} 	return 0; }


#include<bits/stdc++.h>
using namespace std;
#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define sc(n) scanf("%lld", &n)
#include <bits/stdc++.h>
using namespace std;

const long long ALPHABET_SIZE = 3;

// trie node
struct TrieNode{
    TrieNode *children[ALPHABET_SIZE];
    bool isEndOfWord;
};

TrieNode *getNode(void){
	TrieNode *pNode =  new TrieNode;
	pNode->isEndOfWord = false;
	long long i;
	for (i = 0; i < ALPHABET_SIZE; i++){
		pNode->children[i] = NULL;
	}
	return pNode;
}

void insert(TrieNode *root, string key){
	TrieNode *pCrawl = root;
	long long i;
	for (i = 0; i < key.length(); i++){
		long long index = key[i] - 'a';
		if (!pCrawl->children[index]){
			pCrawl->children[index] = getNode();
		}
		pCrawl = pCrawl->children[index];
	}
	pCrawl->isEndOfWord = true;
}
bool flag=false;
void search(TrieNode *root, string key,long long cnt,long long j){
	long long i;
	if(root==NULL){
		return;
	}
	if(j==key.size()){
		if(root->isEndOfWord && cnt==1){
			flag=true;
		}
		return;
	}
	for(i=0;i<3 && !flag;i++){
		if(key[j]==('a'+i)){
			search(root->children[i],key,cnt,j+1);
		}
		else if(cnt==0){
			search(root->children[i],key,cnt+1,j+1);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long long n,m,i,j;
	string s;
	cin>>n>>m;
	TrieNode *root = getNode();
	for(i=0;i<n;i++){
		cin>>s;
		insert(root,s);
	}
	for(i=0;i<m;i++){
		cin>>s;
		flag=false;
		TrieNode *p=root;
		search(p,s,0LL,0LL);
		(flag)?cout<<"YES\n":cout<<"NO\n";
		//search(root,s)?cout<<"YES\n":cout<<"NO\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define sc(n) scanf("%lld", &n)
#include <bits/stdc++.h>
using namespace std;

const long long ALPHABET_SIZE = 3;

// trie node
struct TrieNode{
    TrieNode *children[ALPHABET_SIZE];
    bool isEndOfWord;
};

TrieNode *getNode(void){
	TrieNode *pNode =  new TrieNode;
	pNode->isEndOfWord = false;
	long long i;
	for (i = 0; i < ALPHABET_SIZE; i++){
		pNode->children[i] = NULL;
	}
	return pNode;
}

void insert(TrieNode *root, string key){
	TrieNode *pCrawl = root;
	long long i;
	for (i = 0; i < key.length(); i++){
		long long index = key[i] - 'a';
		if (!pCrawl->children[index]){
			pCrawl->children[index] = getNode();
		}
		pCrawl = pCrawl->children[index];
	}
	pCrawl->isEndOfWord = true;
}
bool flag=false;
void search(TrieNode *root, string key,long long cnt,long long j){
	TrieNode *pCrawl = root;
	long long i;
	if(root==NULL){
		return;
	}
	if(j==key.size() && root->isEndOfWord){
		flag=true;
		return;
	}
	for(i=0;i<2;i++){
		if(key[j]==('a'+i)){
			search(root->children[i],key,cnt,j+1);
		}
		else if(cnt==0){
			search(root->children[i],key,cnt+1,j+1);
		}
		else{
			return;
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long long n,m,i,j;
	string s;
	cin>>n>>m;
	TrieNode *root = getNode();
	for(i=0;i<n;i++){
		cin>>s;
		insert(root,s);
	}
	for(i=0;i<m;i++){
		cin>>s;
		flag=false;
		search(root,s,0LL,0LL);
		(flag)?cout<<"YES\n":cout<<"NO\n";
		//search(root,s)?cout<<"YES\n":cout<<"NO\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#include <cassert>

using namespace std;

// #define endl "\n"
#define bitcount(x) __builtin_popcountll(x)
#define leftbit(x) (x ? 64 - __builtin_clzll(x) : 0)

static const double EPS = 1e-7;

template<class T>
istream & operator >> (istream & is, vector<T> & x) {
	for (auto & item : x)
		is >> item;
	return is;
}

template<class T1, class T2>
ostream & operator << (ostream & os, const pair<T1, T2> & p) {
	os << p.first << ";\t" << p.second;
	return os;
}

template<class T1, class T2>
istream & operator >> (istream & is, pair<T1, T2> & p) {
	is >> p.first >> p.second;
	return is;
}

template <template <typename, typename...> class V, typename... Args>
typename std::enable_if<!std::is_same<std::string, V<Args...>>::value, ostream &>::
type operator << (ostream & os, const V<Args...> & cont) {
	for (const auto & item : cont)
		os << item << "\t";
	os << endl;
	return os;
}

static int _ = []{ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }();

//----------------------------------------------------------------------------------------

// #define int int32_t
#define int int64_t
// #define uint uint32_t
#define uint uint64_t

template<uint M, uint F>
class Dict {
	set<uint> hash_set;
	vector<uint> pows;

public:

	inline uint calc_hash(const string &s) const{
		uint hash = 0;
		for (int i = 0; i < s.size(); ++i)
			hash = (hash + pows[i] * (s[i] - 'a' + 1)) % M;
		return hash;
	}

	Dict(){
		pows.push_back(1);
		for (int i = 1; i < 6 * 1e5; i++)
			pows.push_back((pows.back() * F) % M);
	}

	void insert(const string & s){
		hash_set.insert(calc_hash(s));
	}

	bool find(const string & s) const {

		auto hash = calc_hash(s);

		for (size_t i = 0; i < s.size(); i++)	{
			int delta = 'a' - s[i] - 1;
			for (int j = 0; j < 3; ++j) {
				++delta;
				if (delta != 0) {
					auto tmp_hash = hash;
					tmp_hash += delta * pows[i];
					tmp_hash += 3 * M;
					tmp_hash %= M;

					if (hash_set.find(tmp_hash) != hash_set.end())
						return true;
				}
			}
		}

		return false;
	}
};

int32_t main() {
#ifndef ONLINE_JUDGE
	ifstream ifs("input.txt");
	#define cin ifs
#endif

	int n;
	while(cin >> n) {
		int m;
		cin >> m;

		constexpr uint mod1 = 100050911;
		constexpr uint mod2 = 1000000003;
		constexpr uint mod3 = 100000000000000007;
		constexpr uint mod4 = 100000000000000003;

		constexpr uint fact1 = 5;
		constexpr uint fact2 = 7;

		Dict<mod1, fact1> d1;
		Dict<mod3, fact2> d2;

		int max_size = INT_MIN;
		int min_size = INT_MAX;

		while(n--){
			string s;
			cin >> s;
			max_size = max<int>(max_size, s.size());
			min_size = min<int>(min_size, s.size());

			d1.insert(s);
			d2.insert(s);
		}

		while(m--){
			string s;
			cin >> s;
			bool found = (s.size() >= min_size) and (s.size() <= max_size) and d1.find(s) and d2.find(s);
			cout << (found ? "YES" : "NO") << endl;
		}

#ifdef ONLINE_JUDGE
		break;
#endif
		cout << "------------------------\n"  << flush;
	}

	return 0;
}


#include <bits/stdc++.h>
#include <cassert>

using namespace std;

// #define endl "\n"
#define bitcount(x) __builtin_popcountll(x)
#define leftbit(x) (x ? 64 - __builtin_clzll(x) : 0)

static const double EPS = 1e-7;

template<class T>
istream & operator >> (istream & is, vector<T> & x) {
	for (auto & item : x)
		is >> item;
	return is;
}

template<class T1, class T2>
ostream & operator << (ostream & os, const pair<T1, T2> & p) {
	os << p.first << ";\t" << p.second;
	return os;
}

template<class T1, class T2>
istream & operator >> (istream & is, pair<T1, T2> & p) {
	is >> p.first >> p.second;
	return is;
}

template <template <typename, typename...> class V, typename... Args>
typename std::enable_if<!std::is_same<std::string, V<Args...>>::value, ostream &>::
type operator << (ostream & os, const V<Args...> & cont) {
	for (const auto & item : cont)
		os << item << "\t";
	os << endl;
	return os;
}

static int _ = []{ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }();

//----------------------------------------------------------------------------------------

// #define int int32_t
#define int int64_t
// #define uint uint32_t
#define uint uint64_t

#define mod1 100050911
#define mod2 1000000003
#define mod3 100000000000000007
#define mod4 100000000000000003

class HashSet {
	int F;
	uint M;
	set<uint> hash_set;
	vector<uint> pows;

public:

	uint mod_sub(uint a, uint b) {
		return (a >= b) ? (a - b) : (M - b + a);
	}

	uint calc_hash(const string &s) const {
		uint hash = 0;
		for (size_t i = 0; i < s.size(); i++) {
			hash += (s[i] - 'a' + 1) * pows[i];
			hash %= M;
		}
		return hash;
	}

	HashSet(int ml, uint md, int maxPow) : F(ml), M(md) {
		pows.push_back(1);
		for (int i = 1; i < maxPow; i++)
			pows.push_back((pows.back() * F) % M);
	}

	void insert(const string & s){
		hash_set.insert(calc_hash(s));
	}

	bool find(const string &s) const {

		auto hash = calc_hash(s);

		for (size_t i = 0; i < s.size(); i++)	{
			int delta = 'a' - s[i] - 1;
			for (int j = 0; j < 3; ++j) {
				++delta;
				if (delta != 0) {
					auto tmp_hash = hash;
					tmp_hash += delta * pows[i];
					tmp_hash += 3 * M;
					tmp_hash %= M;

					if (hash_set.find(tmp_hash) != hash_set.end())
						return true;
				}
			}
		}

		return false;
	}
};

int32_t main() {
#ifndef ONLINE_JUDGE
	ifstream ifs("input.txt");
	#define cin ifs
#endif

	int n;
	while(cin >> n) {
	int m;
	cin >> m;

	vector<string> strings;
	size_t max_size = 0;
	size_t min_size = INT_MAX;
	string s;

	int max_pow = 6 * 1e5;

	HashSet d1(5, mod1, max_pow), d2(7, mod3, max_pow);

	for (size_t i = 0; i < n; i++) {
		cin >> s;
		max_size = max(max_size, s.size());
		min_size = min(min_size, s.size());

		d1.insert(s);
		d2.insert(s);
	}

	for (size_t i = 0; i < m; i++) {
		cin >> s;
		bool found = s.size() >= min_size && s.size() <= max_size and d1.find(s) and d2.find(s);
		cout << (found ? "YES" : "NO") << endl;
	}

#ifdef ONLINE_JUDGE
		break;
#endif
		cout << "------------------------\n"  << flush;
	}

	return 0;
}


#include <bits/stdc++.h>
#include <cassert>

using namespace std;

// #define endl "\n"
#define bitcount(x) __builtin_popcountll(x)
#define leftbit(x) (x ? 64 - __builtin_clzll(x) : 0)

static const double EPS = 1e-7;

template<class T>
istream & operator >> (istream & is, vector<T> & x) {
	for (auto & item : x)
		is >> item;
	return is;
}

template<class T1, class T2>
ostream & operator << (ostream & os, const pair<T1, T2> & p) {
	os << p.first << ";\t" << p.second;
	return os;
}

template<class T1, class T2>
istream & operator >> (istream & is, pair<T1, T2> & p) {
	is >> p.first >> p.second;
	return is;
}

template <template <typename, typename...> class V, typename... Args>
typename std::enable_if<!std::is_same<std::string, V<Args...>>::value, ostream &>::
type operator << (ostream & os, const V<Args...> & cont) {
	for (const auto & item : cont)
		os << item << "\t";
	os << endl;
	return os;
}

static int _ = []{ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }();

//----------------------------------------------------------------------------------------

// #define int int32_t
#define int int64_t
// #define uint uint32_t
#define uint uint64_t

#define mod1 100050911
#define mod2 1000000003
#define mod3 100000000000000007
#define mod4 100000000000000003

class Dict {
	int F;
	uint M;
	set<uint> hash_set;
	vector<uint> pows;

public:

	uint mod_sub(uint a, uint b) {
		return (a >= b) ? (a - b) : (M - b + a);
	}

	uint calc_hash(const string &s) const {
		uint hash = 0;
		for (size_t i = 0; i < s.size(); i++) {
			hash += (s[i] - 'a' + 1) * pows[i];
			hash %= M;
		}
		return hash;
	}

	Dict(int ml, uint md, int maxPow) : F(ml), M(md) {
		pows.push_back(1);
		for (int i = 1; i < maxPow; i++)
			pows.push_back((pows.back() * F) % M);
	}

	void insert(const string & s){
		hash_set.insert(calc_hash(s));
	}

	bool find(const string & s) const {

		auto hash = calc_hash(s);

		for (size_t i = 0; i < s.size(); i++)	{
			int delta = 'a' - s[i] - 1;
			for (int j = 0; j < 3; ++j) {
				++delta;
				if (delta != 0) {
					auto tmp_hash = hash;
					tmp_hash += delta * pows[i];
					tmp_hash += 3 * M;
					tmp_hash %= M;

					if (hash_set.find(tmp_hash) != hash_set.end())
						return true;
				}
			}
		}

		return false;
	}
};

int32_t main() {
#ifndef ONLINE_JUDGE
	ifstream ifs("input.txt");
	#define cin ifs
#endif

	int n;
	while(cin >> n) {
	int m;
	cin >> m;

	vector<string> strings;
	size_t max_size = 0;
	size_t min_size = INT_MAX;
	string s;

	int max_pow = 6 * 1e5;

	Dict d1(5, mod1, max_pow), d2(7, mod3, max_pow);

	for (size_t i = 0; i < n; i++) {
		cin >> s;
		max_size = max(max_size, s.size());
		min_size = min(min_size, s.size());

		d1.insert(s);
		d2.insert(s);
	}

	for (size_t i = 0; i < m; i++) {
		cin >> s;
		bool found = s.size() >= min_size && s.size() <= max_size and d1.find(s) and d2.find(s);
		cout << (found ? "YES" : "NO") << endl;
	}

#ifdef ONLINE_JUDGE
		break;
#endif
		cout << "------------------------\n"  << flush;
	}

	return 0;
}


#include <bits/stdc++.h>
#include <cassert>

using namespace std;

// #define endl "\n"
#define bitcount(x) __builtin_popcountll(x)
#define leftbit(x) (x ? 64 - __builtin_clzll(x) : 0)

static const double EPS = 1e-7;

template<class T>
istream & operator >> (istream & is, vector<T> & x) {
	for (auto & item : x)
		is >> item;
	return is;
}

template<class T1, class T2>
ostream & operator << (ostream & os, const pair<T1, T2> & p) {
	os << p.first << ";\t" << p.second;
	return os;
}

template<class T1, class T2>
istream & operator >> (istream & is, pair<T1, T2> & p) {
	is >> p.first >> p.second;
	return is;
}

template <template <typename, typename...> class V, typename... Args>
typename std::enable_if<!std::is_same<std::string, V<Args...>>::value, ostream &>::
type operator << (ostream & os, const V<Args...> & cont) {
	for (const auto & item : cont)
		os << item << "\t";
	os << endl;
	return os;
}

static int _ = []{ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }();

//----------------------------------------------------------------------------------------

// #define int int32_t
#define int int64_t
// #define uint uint32_t
#define uint uint64_t

template<uint M, uint F>
class Dict{
	unordered_map<int, unordered_set<uint>> len_to_hashes;

	static uint mult_pow(const uint p){
		static vector<uint> pows = {1};
		while(pows.size() <= p)
			pows.push_back((pows.back() * F) % M);
		return pows[p];
	}

	static inline uint calc_hash(const string & s){
		uint hash = 0;
		for (int i = 0; i < s.size(); ++i)
			hash = (hash + (mult_pow(i) * (s[i] - 'a' + 1)) % M) % M;
		return hash;
	}

	static inline uint mod_sub(uint a, uint b) {
		return (a >= b) ? (a - b) : (M - b + a);
	}

public:

	void insert(const string & s){
		len_to_hashes[s.size()].insert(calc_hash(s));
	}

	bool find(const string & s) const{

		auto hashes_it = len_to_hashes.find(s.size());
		if (hashes_it == len_to_hashes.end())
			return false;

		auto hash_set = hashes_it->second;
		auto hash = calc_hash(s);
		if (hash_set.find(hash) != hash_set.end())
			return true;

		for (size_t i = 0; i < s.size(); i++)	{
			int delta = 'a' - s[i] - 1;
			for (int j = 0; j < 3; ++j) {
				++delta;
				if (delta) {
					auto tmp_hash = (delta * mult_pow(i) + 3 * M + hash) % M;
					if (hash_set.find(tmp_hash) != hash_set.end())
						return true;
				}
			}
		}

		return false;
	}
};

int32_t main() {
#ifndef ONLINE_JUDGE
	ifstream ifs("input.txt");
	#define cin ifs
#endif

	int n;
	while(cin >> n) {
		int m;
		cin >> m;

		constexpr uint mod1 = 100050911ULL;
		constexpr uint mod2 = 1000000003ULL;
		constexpr uint mod3 = 100000000000000007ULL;
		constexpr uint mod4 = 100000000000000003ULL;

		constexpr uint fact1 = 5;
		constexpr uint fact2 = 7;

		Dict<mod1, fact1> d1;
		Dict<mod3, fact2> d2;

		while(n--){
			string s;
			cin >> s;

			d1.insert(s);
			d2.insert(s);
		}

		while(m--){
			string s;
			cin >> s;
			// cout << s << endl;

			bool found = d1.find(s) and d2.find(s);
			cout << (found ? "YES" : "NO") << endl;
		}

#ifdef ONLINE_JUDGE
		break;
#endif
		cout << "------------------------\n"  << flush;
	}

	return 0;
}


#include <bits/stdc++.h>
#include <cassert>

using namespace std;

// #define endl "\n"
#define bitcount(x) __builtin_popcountll(x)
#define leftbit(x) (x ? 64 - __builtin_clzll(x) : 0)

static const double EPS = 1e-7;

template<class T>
istream & operator >> (istream & is, vector<T> & x) {
	for (auto & item : x)
		is >> item;
	return is;
}

template<class T1, class T2>
ostream & operator << (ostream & os, const pair<T1, T2> & p) {
	os << p.first << ";\t" << p.second;
	return os;
}

template<class T1, class T2>
istream & operator >> (istream & is, pair<T1, T2> & p) {
	is >> p.first >> p.second;
	return is;
}

template <template <typename, typename...> class V, typename... Args>
typename std::enable_if<!std::is_same<std::string, V<Args...>>::value, ostream &>::
type operator << (ostream & os, const V<Args...> & cont) {
	for (const auto & item : cont)
		os << item << "\t";
	os << endl;
	return os;
}

static int _ = []{ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }();

//----------------------------------------------------------------------------------------

// #define int int32_t
#define int int64_t
// #define uint uint32_t
#define uint uint64_t

template<uint M, uint F>
class Dict{
	unordered_map<int, unordered_set<uint>> len_to_hashes;

	static uint mult_pow(const uint p){
		static vector<uint> pows = {1};
		while(pows.size() <= p)
			pows.push_back((pows.back() * F) % M);
		return pows[p];
	}

	static inline uint calc_hash(const string & s){
		uint hash = 0;
		for (int i = 0; i < s.size(); ++i)
			hash = (hash + (mult_pow(i) * (s[i] - 'a' + 1)) % M) % M;
		return hash;
	}

	static inline uint mod_sub(uint a, uint b) {
		return (a >= b) ? (a - b) : (M - b + a);
	}

public:

	void insert(const string & s){
		len_to_hashes[s.size()].insert(calc_hash(s));
	}

	bool find(const string & s) const{

		auto hashes_it = len_to_hashes.find(s.size());
		if (hashes_it == len_to_hashes.end())
			return false;

		auto hash_set = hashes_it->second;
		auto hash = calc_hash(s);
		if (hash_set.find(hash) != hash_set.end())
			return true;

		for (size_t i = 0; i < s.size(); i++)	{
			int delta = 'a' - s[i] - 1;
			for (int j = 0; j < 3; ++j) {
				++delta;
				if (delta) {
					auto tmp_hash = (mult_pow(i) * delta + 3 * M + hash) % M;
					if (hash_set.find(tmp_hash) != hash_set.end())
						return true;
				}
			}
		}

		return false;
	}
};

int32_t main() {
#ifndef ONLINE_JUDGE
	ifstream ifs("input.txt");
	#define cin ifs
#endif

	int n;
	while(cin >> n) {
		int m;
		cin >> m;

		constexpr uint mod1 = 100050911ULL;
		constexpr uint mod2 = 1000000003ULL;
		constexpr uint mod3 = 100000000000000007ULL;
		constexpr uint mod4 = 100000000000000003ULL;

		constexpr uint fact1 = 5;
		constexpr uint fact2 = 7;

		Dict<mod1, fact1> d1;
		Dict<mod3, fact2> d2;

		int max_size = INT_MIN;
		int min_size = INT_MAX;

		while(n--){
			string s;
			cin >> s;

			max_size = max<int>(max_size, s.size());
			min_size = min<int>(min_size, s.size());

			d1.insert(s);
			d2.insert(s);
		}

		while(m--){
			string s;
			cin >> s;
			// cout << s << endl;

			bool found = (s.size() >= min_size) and (s.size() <= max_size) and d1.find(s) and d2.find(s);
			cout << (found ? "YES" : "NO") << endl;
		}

#ifdef ONLINE_JUDGE
		break;
#endif
		cout << "------------------------\n"  << flush;
	}

	return 0;
}


#include <bits/stdc++.h>
#include <cassert>

using namespace std;

// #define endl "\n"
#define bitcount(x) __builtin_popcountll(x)
#define leftbit(x) (x ? 64 - __builtin_clzll(x) : 0)

static const double EPS = 1e-7;

template<class T>
istream & operator >> (istream & is, vector<T> & x) {
	for (auto & item : x)
		is >> item;
	return is;
}

template<class T1, class T2>
ostream & operator << (ostream & os, const pair<T1, T2> & p) {
	os << p.first << ";\t" << p.second;
	return os;
}

template<class T1, class T2>
istream & operator >> (istream & is, pair<T1, T2> & p) {
	is >> p.first >> p.second;
	return is;
}

template <template <typename, typename...> class V, typename... Args>
typename std::enable_if<!std::is_same<std::string, V<Args...>>::value, ostream &>::
type operator << (ostream & os, const V<Args...> & cont) {
	for (const auto & item : cont)
		os << item << "\t";
	os << endl;
	return os;
}

static int _ = []{ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }();

//----------------------------------------------------------------------------------------

// #define int int32_t
#define int int64_t
// #define uint uint32_t
#define uint uint64_t

template<uint M, uint F>
class Dict {
	unordered_map<int, unordered_set<uint>> len_to_hashes;
	vector<uint> pows;

public:

	inline uint calc_hash(const string &s) const{
		uint hash = 0;
		for (int i = 0; i < s.size(); ++i)
			hash = (hash + pows[i] * (s[i] - 'a' + 1)) % M;
		return hash;
	}

	Dict(){
		pows.push_back(1);
		for (int i = 1; i < 6 * 1e5; i++)
			pows.push_back((pows.back() * F) % M);
	}

	void insert(const string & s){
		len_to_hashes[s.size()].insert(calc_hash(s));
	}

	bool find(const string & s) const{

		auto hashes_it = len_to_hashes.find(s.size());
		if (hashes_it == len_to_hashes.end())
			return false;

		auto hash_set = hashes_it->second;
		auto hash = calc_hash(s);
		if (hash_set.find(hash) != hash_set.end())
			return true;

		for (size_t i = 0; i < s.size(); i++)	{
			int delta = 'a' - s[i] - 1;
			for (int j = 0; j < 3; ++j) {
				++delta;
				if (delta) {
					auto tmp_hash = (pows[i] * delta + M * 3 + hash) % M;
					if (hash_set.find(tmp_hash) != hash_set.end())
						return true;
				}
			}
		}

		return false;
	}
};

int32_t main() {
#ifndef ONLINE_JUDGE
	ifstream ifs("input.txt");
	#define cin ifs
#endif

	int n;
	while(cin >> n) {
		int m;
		cin >> m;

		constexpr uint mod1 = 100050911;
		constexpr uint mod2 = 1000000003;
		constexpr uint mod3 = 100000000000000007;
		constexpr uint mod4 = 100000000000000003;

		constexpr uint fact1 = 5;
		constexpr uint fact2 = 7;

		Dict<mod1, fact1> d1;
		Dict<mod3, fact2> d2;

		int max_size = INT_MIN;
		int min_size = INT_MAX;

		while(n--){
			string s;
			cin >> s;
			max_size = max<int>(max_size, s.size());
			min_size = min<int>(min_size, s.size());

			d1.insert(s);
			d2.insert(s);
		}

		while(m--){
			string s;
			cin >> s;
			bool found = (s.size() >= min_size) and (s.size() <= max_size) and d1.find(s) and d2.find(s);
			cout << (found ? "YES" : "NO") << endl;
		}

#ifdef ONLINE_JUDGE
		break;
#endif
		cout << "------------------------\n"  << flush;
	}

	return 0;
}


import sys
import heapq
range = xrange
input = raw_input

n = int(input())
A = [int(x) - 1 for x in input().split()]
root = A[0]

counter = [0]*n
for a in A:
    counter[a] = 1

heap = [i for i in range(n) if counter[i] == 0]
heapq.heapify(heap)

pairs = []

for a in reversed(A):
    if heap:
        val = heapq.heappop(heap)
        pairs.append((val, a))
        if a != root:
            heapq.heappush(heap, a)
    else:
        print -1
        sys.exit()
pairs.reverse()

children = [[] for _ in range(n)]
for u,v in pairs:
    children[v].append(u)

bfs = [root]
order = [-1]*n
counter = 0
for node in bfs:
    if len(bfs) > n:
        print -1
        sys.exit()
    order[node] = counter
    counter += 1
    bfs += children[node]

maxind = [i for i in range(n)]
for node in reversed(bfs):
    if children[node]:
        maxind[node] = max(maxind[node], max(maxind[child] for child in children[node]))

for i in range(n - 2):
    u,v = pairs[i]
    x,y = pairs[i + 1]

    score1 = maxind[u]
    score2 = maxind[x]
    order1 = order[u]
    order2 = order[x]
    if score1 < score2 or (score1 == score2 and order1 > order2):
        print -1
        sys.exit()

print root + 1
print '\n'.join('%d %d' % (u + 1, v + 1) for u,v in pairs)


import sys
import heapq
range = xrange
input = raw_input

n = int(input())
A = [int(x) - 1 for x in input().split()]
root = A[0]

counter = [0]*n
for a in A:
    counter[a] += 1

heap = [i for i in range(n) if counter[i] == 0]
heapq.heapify(heap)

pairs = []

for a in reversed(A):
    if heap:
        val = heapq.heappop(heap)
        pairs.append((val, a))
        counter[a] -= 1
        if counter[a] == 0:
            heapq.heappush(heap, a)
    else:
        print -1
        sys.exit()
pairs.reverse()

print root + 1
print '\n'.join('%d %d' % (u + 1, v + 1) for u,v in pairs)


import sys
import heapq
range = xrange
input = raw_input

n = int(input())
A = [int(x) - 1 for x in input().split()]
root = A[0]

counter = [0]*n
for a in A:
    counter[a] = 1

heap = [i for i in range(n) if counter[i] == 0]
heapq.heapify(heap)

pairs = []

for a in reversed(A):
    if heap:
        val = heapq.heappop(heap)
        pairs.append((val, a))
        if a != root:
            heapq.heappush(heap, a)
    else:
        print -1
        sys.exit()
pairs.reverse()

children = [[] for _ in range(n)]
for u,v in pairs:
    children[v].append(u)

bfs = [root]
order = [-1]*n
counter = 0
for node in bfs:
    order[node] = counter
    counter += 1
    bfs += children[node]

maxind = [i for i in range(n)]
for node in reversed(bfs):
    if children[node]:
        maxind[node] = max(maxind[node], max(maxind[child] for child in children[node]))

for i in range(n - 2):
    u,v = pairs[i]
    x,y = pairs[i + 1]

    score1 = maxind[u]
    score2 = maxind[x]
    order1 = order[u]
    order2 = order[x]
    if score1 < score2 or (score1 == score2 and order1 > order2):
        print -1
        sys.exit()

print root + 1
print '\n'.join('%d %d' % (u + 1, v + 1) for u,v in pairs)


import sys
import heapq
range = xrange
input = raw_input

n = int(input())
A = [int(x) - 1 for x in input().split()]
root = A[0]

counter = [0]*n
for a in A:
    counter[a] += 1

heap = [i for i in range(n) if counter[i] == 0]
heapq.heapify(heap)

pairs = []

for a in reversed(A):
    if heap:
        val = heapq.heappop(heap)
        pairs.append((val, a))
        counter[a] -= 1
        if counter[a] == 0:
            heapq.heappush(heap, a)
    else:
        print -1
        sys.exit()
pairs.reverse()

children = [[] for _ in range(n)]
for u,v in pairs:
    children[v].append(u)

bfs = [root]
order = [-1]*n
counter = 0
for node in bfs:
    if len(bfs) > n:
        print -1
        sys.exit()
    order[node] = counter
    counter += 1
    bfs += children[node]

maxind = [i for i in range(n)]
for node in reversed(bfs):
    if children[node]:
        maxind[node] = max(maxind[node], max(maxind[child] for child in children[node]))

for i in range(n - 2):
    u,v = pairs[i]
    x,y = pairs[i + 1]

    score1 = maxind[u]
    score2 = maxind[x]
    order1 = order[u]
    order2 = order[x]
    if score1 < score2 or (score1 == score2 and order1 > order2):
        print -1
        sys.exit()

print root + 1
print '\n'.join('%d %d' % (u + 1, v + 1) for u,v in pairs)


n = int(input())
ls = list(map(int, input().split()))
parent = {}
seen = set()
seen.add(ls[0])
lookf = n

for i, e in enumerate(ls):
    #print(lookf,e)
    if e in seen:
        while lookf in seen:
            lookf -= 1
        parent[lookf] = e
        lastarc = (lookf, e)
    else:
        parent[e] = lastarc[1]
        parent[lastarc[0]] = e
        lastarc = (lastarc[0], e)
        seen.add(e)
    seen.add(lookf)

print(ls[0])
for k in parent:
    print(k, parent[k])
#print(parent)


n = int(input())

a = list(map(int,input().split()))

dic = {}
uexmax = n
ans = []

for i in range(n-1):

    if i == 0:
        dic[a[i]] = 1

    else:

        if a[i] in dic:
            dic[uexmax] = 1
            ans.append([ a[i-1] , uexmax ])
        else:
            dic[a[i]] = 1
            ans.append([ a[i-1] , a[i] ])

    while uexmax in dic:
        uexmax -= 1

ans.append ( [a[-1] , uexmax] )

print (a[0])

for i in range(n-1):
    print (" ".join(map(str,ans[i])))


n = int(input())
v = list(map(int, input().split()))
vaz = [0 for x in range(n+10)]
vaz1 = [0 for x in range(2*n+10)]
root = v[0]
node = n
g = []
for i in range(0,n+1):
    g.append([])
vaz1[root]=1
last = root
pz = n
for i in range(1,n-1):
    if vaz1[v[i]]==1:
        while(vaz1[pz]==1):
            pz-=1
        g[last].append(pz)
        vaz1[pz]=1
        last=v[i]
    else:
        vaz1[v[i]]=1
        g[last].append(v[i])
        last = v[i]
while(vaz1[pz]==1):
    pz-=1
g[last].append(pz)
v1 = []
v1.append(root)
vaz[root]=1
pz = 0
while pz<len(v1):
    node = v1[pz]
    pz +=1
    for vec in g[node]:
        if vaz[vec]==0:
            vaz[vec]=1
            v1.append(vec)
ok=0
for i in range(1,n+1):
    if vaz[i]==0:
        ok=1
if ok==1:
    print("-1")
else:
    print(str(root))
    for i in range(1,n+1):
        for x in g[i]:
            print(str(i)+" "+str(x))


def go():
    n = int(input())
    a = list(map(lambda s: int(s) - 1, input().split()))

    done = [False] * n

    root = a[0]
    done[root] = True

    target = n - 1
    while done[target]: target -= 1

    parent = [-1] * n
    hanging = root

    def set_parent(x, par):
        if parent[x] != -1:
            return False
        else:
            parent[x] = par
            done[x] = True
            return True

    i = 0
    while i < n - 2:
        i += 1
        if a[i] == target or done[a[i]]:
            son=target
        else:
            son=a[i]
        if not set_parent(son, hanging):
            print (-1)
            return
        while done[target]: target -= 1
        hanging = a[i]
    parent[target] = hanging

    print(root)
    for a,b in enumerate(parent):
        if b!=-1:
            print (a+1,b+1)

go()


def go():
    n = int(input())
    a = list(map(lambda s: int(s) - 1, input().split()))

    done = [False] * n

    root = a[0]
    done[root] = True

    target = n - 1
    while done[target]: target -= 1

    parent = [-1] * n
    hanging = root

    def set_parent(x, par):
        if parent[x] != -1:
            return False
        else:
            parent[x] = par
            done[x] = True
            return True

    i = 0
    while i < n - 2:
        i += 1
        if a[i] == target or done[a[i]]:
            son=target
        else:
            son=a[i]
        if not set_parent(son, hanging):
            print (-1)
            return
        while done[target]: target -= 1
        hanging = a[i]
    parent[target] = hanging

    print(root+1)
    for a,b in enumerate(parent):
        if b!=-1:
            print (a+1,b+1)

go()


n = int(input())
a = list(map(int, input().split()))

used = [0]*(n+1)
print(a[0])
bigger = n
for x, y in zip(a, a[1:]):
    used[x] = 1
    if not used[y]:
        print(x, y)
    else:
        while used[bigger]:
            bigger -= 1
        print(x, bigger)
        used[bigger] = 1

while used[bigger]:
    bigger -= 1
print(a[-1], bigger)


n = int(input())
a = list(map(int, input().split()))

used = [0]*(n+1)
print(a[0])
bigger = n
for x, y in zip(a, a[1:]):
    used[x] = 1
    if not used[y]:
        print(x, y)
    else:
        while used[bigger]:
            bigger -= 1
        print(x, bigger)
        used[bigger] = 1

used[a[-1]] = 1
while used[bigger]:
    bigger -= 1
print(a[-1], bigger)


"""n=int(input())
s=[int(x) for x in input().split()]

print(s[0])

pos=[0]*(n+1)
L=[]
for i in range(0,len(s)):
    if(pos[s[i]]==0):
        L.append(s[i])
        pos[s[i]]=1
    else:
        for j in range(n,0,-1):
            if(pos[j]==0):
                L.append(j)
                pos[j]=1
                break
        for j in range(0,len(L)-1):
            print(L[j],L[j+1])
        L=[s[i]]

for j in range(n,0,-1):
    if(pos[j]==0):
        L.append(j)
        pos[j]=1
        break
for j in range(0,len(L)-1):
    print(L[j],L[j+1])
"""

n=int(input())
s=[int(x) for x in input().split()]

print(s[0])

pos=[0]*(n+1)
L=[]
ptr=n
for i in range(0,len(s)):
    if(pos[s[i]]==0):
        L.append(s[i])
        pos[s[i]]=1
    else:
        for j in range(ptr,0,-1):
            if(pos[j]==0):
                L.append(j)
                pos[j]=1
                ptr=j-1
                break
        for j in range(0,len(L)-1):
            print(L[j],L[j+1])
        L=[s[i]]

for j in range(ptr,0,-1):
    if(pos[j]==0):
        L.append(j)
        pos[j]=1
        ptr=j-1
        break
for j in range(0,len(L)-1):
    print(L[j],L[j+1])


n=int(input())
s=[int(x) for x in input().split()]

print(s[0])

pos=[0]*(n+1)
L=[]
for i in range(0,len(s)):
    if(pos[s[i]]==0):
        L.append(s[i])
        pos[s[i]]=1
    else:
        for j in range(n,0,-1):
            if(pos[j]==0):
                L.append(j)
                pos[j]=1
                break
        for j in range(0,len(L)-1):
            print(L[j],L[j+1])
        L=[s[i]]

for j in range(n,0,-1):
    if(pos[j]==0):
        L.append(j)
        pos[j]=1
        break
for j in range(0,len(L)-1):
    print(L[j],L[j+1])


from heapq import heappush, heappop
from collections import Counter

def main():
    n = int(input())
    aa = [int(a)-1 for a in input().split()]
    saa = set(aa)
    caa = Counter(aa)
    ready = []
    for i in range(n):
        if i not in saa:
            heappush(ready, (i,i))
    cimp = 0
    edges = []
    for a in aa[::-1]:
        imp, c = heappop(ready)
        if imp < cimp:
            print(-1)
            return
        edges.append((a, c))
        caa[a] -=1
        if caa[a] == 0:
            heappush(ready, (max(a, imp), a))
    print(aa[0]+1)
    for p,c in edges:
        print(p+1, c+1)

if __name__ == "__main__":
    main()


from heapq import heappush, heappop
from collections import Counter

def main():
    n = int(input())
    aa = [int(a)-1 for a in input().split()]
    saa = set(aa)
    caa = Counter(aa)
    ready = []
    for i in range(n):
        if i not in saa:
            heappush(ready, (i,i))
    print(aa[0] + 1)
    for a in aa[::-1]:
        imp, c = heappop(ready)
        print(a, c)
        caa[a] -=1
        if caa[a] == 0:
            heappush(ready, (max(a, imp), a))

if __name__ == "__main__":
    main()


from heapq import heappush, heappop
from collections import Counter

def main():
    n = int(input())
    aa = [int(a)-1 for a in input().split()]
    saa = set(aa)
    caa = Counter(aa)
    ready = []
    for i in range(n):
        if i not in saa:
            heappush(ready, (i,i))
    print(aa[0] + 1)
    for a in aa[::-1]:
        imp, c = heappop(ready)
        print(a+1, c+1)
        caa[a] -=1
        if caa[a] == 0:
            heappush(ready, (max(a, imp), a))

if __name__ == "__main__":
    main()


import java.lang.StringBuilder
import java.util.*

fun main() {
    val n = readLine()!!.toInt()
    val tokenizer = StringTokenizer(readLine()!!)
    val a = IntArray(n - 1) { tokenizer.nextToken().toInt() }
    val maxContained = IntArray(n + 1)
    for (j in 1..n) {
        maxContained[j] = j
    }
    val lastIx = IntArray(n + 1) { -1 }
    for (j in 0 until n - 1) {
        lastIx[a[j]] = j
    }
    val disp = TreeSet<Int>(Comparator.comparingInt { maxContained[it] })
    for (j in 1..n) {
        if (lastIx[j] == -1) {
            disp.add(j)
        }
    }
    val parent = IntArray(n + 1)
    for (j in 0 until n - 1) {
        val k = disp.first()
        //println("j = $j, k = $k")
        disp.remove(k)
        if (maxContained[k] > maxContained[a[j]]) {
            maxContained[a[j]] = maxContained[k]
        }
        parent[k] = a[j]
        if (lastIx[a[j]] == j) {
            disp.add(a[j])
        }
    }
    val out = StringBuilder()
    for (j in 1..n) {
        if (parent[j] == 0) {
            out.appendln(j)
        }
    }
    for (j in 1..n) {
        if (parent[j] != 0) {
            out.append(parent[j]).append(' ').appendln(j)
        }
    }
    print(out)
}


import java.lang.StringBuilder
import java.util.*
import kotlin.Comparator

fun main() {
    val n = readLine()!!.toInt()
    val tokenizer = StringTokenizer(readLine()!!)
    val a = IntArray(n - 1) { tokenizer.nextToken().toInt() }
    val maxContained = IntArray(n + 1)
    for (j in 1..n) {
        maxContained[j] = j
    }
    val lastIx = IntArray(n + 1) { -1 }
    for (j in 0 until n - 1) {
        lastIx[a[j]] = j
    }
    val disp = TreeSet<Int>(Comparator { j1, j2 -> maxContained[j1] - maxContained[j2]})
    for (j in 1..n) {
        if (lastIx[j] == -1) {
            disp.add(j)
        }
    }
    val parent = IntArray(n + 1)
    for (j in 0 until n - 1) {
        val k = disp.first()
        //println("j = $j, k = $k")
        disp.remove(k)
        if (maxContained[k] > maxContained[a[j]]) {
            maxContained[a[j]] = maxContained[k]
        }
        parent[k] = a[j]
        if (lastIx[a[j]] == j) {
            disp.add(a[j])
        }
    }
    val out = StringBuilder()
    for (j in 1..n) {
        if (parent[j] == 0) {
            out.appendln(j)
        }
    }
    for (j in 1..n) {
        if (parent[j] != 0) {
            out.append(parent[j]).append(' ').appendln(j)
        }
    }
    print(out)
}


import java.lang.StringBuilder
import java.util.*
import kotlin.Comparator

fun main() {
    val n = readLine()!!.toInt()
    val tokenizer = StringTokenizer(readLine()!!)
    val a = IntArray(n - 1) { tokenizer.nextToken().toInt() }.reversed()
    val maxContained = IntArray(n + 1)
    for (j in 1..n) {
        maxContained[j] = j
    }
    val lastIx = IntArray(n + 1) { -1 }
    for (j in 0 until n - 1) {
        lastIx[a[j]] = j
    }
    val disp = TreeSet<Int>(Comparator { j1, j2 -> maxContained[j1] - maxContained[j2]})
    for (j in 1..n) {
        if (lastIx[j] == -1) {
            disp.add(j)
        }
    }
    val parent = IntArray(n + 1)
    for (j in 0 until n - 1) {
        val k = disp.first()
        //println("j = $j, k = $k")
        disp.remove(k)
        if (maxContained[k] > maxContained[a[j]]) {
            maxContained[a[j]] = maxContained[k]
        }
        parent[k] = a[j]
        if (lastIx[a[j]] == j) {
            disp.add(a[j])
        }
    }
    val out = StringBuilder()
    for (j in 1..n) {
        if (parent[j] == 0) {
            out.appendln(j)
        }
    }
    for (j in 1..n) {
        if (parent[j] != 0) {
            out.append(parent[j]).append(' ').appendln(j)
        }
    }
    print(out)
}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeSet;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author xylenox
 */
public class f {
    public static void main(String[] args) {
        FS in = new FS(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        TreeSet<Integer> notFound = new TreeSet<>();
        for(int i = 0; i < n; i++) notFound.add(i+1);
        int prev = in.nextInt();
        notFound.remove(prev);
        out.println(prev);
        for(int i = 1; i < n-1; i++) {
            int next = in.nextInt();
            if(!notFound.contains(next)) {
                out.println(prev + " " + notFound.pollLast());
            } else {
                out.println(prev + " " + next);
            }
            notFound.remove(next);
            prev = next;
        }
        out.println(prev + " " + notFound.pollLast());
        out.close();
    }

    static class FS {
        BufferedReader in;
        StringTokenizer token;

        public FS(InputStream st) {
            in = new BufferedReader(new InputStreamReader(st));
        }

        public String next() {
            if(token == null || !token.hasMoreElements()) {
                try {
                    token = new StringTokenizer(in.readLine());
                } catch(Exception e) {}
                return next();
            }
            return token.nextToken();
        }

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

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


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

// written by luchy0120

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

        new Main().run();
    }

    static int groups = 0;
    static int[] fa;
    static int[] sz;

    static void init(int n) {
        groups = n;
        fa = new int[n];
        for (int i = 1; i < n; ++i) {
            fa[i] = i;
        }
        sz = new int[n];
        Arrays.fill(sz, 1);
    }

    static int root(int p) {
        while (p != fa[p]) {
            fa[p] = fa[fa[p]];
            p = fa[p];
        }
        return p;
    }

    static void combine(int p, int q) {
        int i = root(p);
        int j = root(q);
        if (i == j) {
            return;
        }
        if (sz[i] < sz[j]) {
            fa[i] = j;
            sz[j] += sz[i];
        } else {
            fa[j] = i;
            sz[i] += sz[j];
        }
        groups--;
    }

    int color[],dfn[],low[],stack[],cnt[];
    boolean vis[];
    boolean iscut[];
    int deep,top,n,m,sum,ans;
    List<Integer> g[];

    void tarjan(int u,int fa) {
        int child = 0;
        dfn[u]=++deep;
        low[u]=deep;
        vis[u]=true;
        stack[++top]=u;
        int sz=g[u].size();
        for(int i=0;i<sz;i++) {
            int v =g[u].get(i);
            if(v==fa) continue;
            if(dfn[v]==0) {
                child++;
                tarjan(v,u);
                low[u]=Math.min(low[u],low[v]);
            } else {
                if(vis[v]) {
                    low[u]=Math.min(low[u],low[v]);
                }
            }
        }
        if(fa<0&&child==1){
            iscut[u] =true;
        }

        if(dfn[u]==low[u]) {
            iscut[u] = true;
            color[u]=++sum;
            vis[u]=false;
            while(stack[top]!=u) {
                color[stack[top]]=sum;
                vis[stack[top--]]=false;
            }
            top--;
        }
    }

    int h[],to[],ne[];int ct =0;
    void add(int u,int v){
        u--;v--;
        to[ct] = v;
        ne[ct] = h[u];
        h[u] = ct++;
    }

    void graph(int n,int m){
        h = new int[n];
        Arrays.fill(h,-1);
        ne = new int[2*m];
        to = new int[2*m];
        ct = 0;
    }

    static long mul(long a, long b, long p)
    {
        long res=0,base=a;
        while(b>0)
        {
            if((b&1L)>0)
                res=(res+base)%p;
            base=(base+base)%p;
            b>>=1;
        }
        return res;
    }

    static long mod_pow(long k,long n,long p){
        long res = 1L;
        long temp = (k%p+p)%p;
        while(n!=0L){
            if((n&1L)==1L){
                res = ((res*temp)%p+p)%p;
            }
            temp = ((temp * temp)%p+p)%p;
            n = n>>1L;
        }
        return res%p;
    }
    public static String roundS(double result, int scale){
        String fmt = String.format("%%.%df", scale);
        return String.format(fmt, result);
    }

    int x[];
    int y[];
    int k ;
    int r = 1000000000;
    int[][] pos;

    boolean gd(int i){
        if(pos[i][0]<pos[i][1]) return false;
        if(pos[i][2]>pos[i][3]) return false;
        return true;
    }

    int area(int i){
        if(pos[i][0]<=pos[i][1]) return 0;
        if(pos[i][2]>=pos[i][3]) return 0;
        return (pos[i][0]-pos[i][1])*(pos[i][3]-pos[i][2]);
    }

    boolean in(int i,int y,int x){
        return y<=pos[i][0]&&y>=pos[i][1] && x<=pos[i][3] && x>= pos[i][2];
    }

    boolean ck(int i,int j){
        return !in(i, pos[j][0],pos[j][3]) &&
        !in(i, pos[j][0],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][3]);
    }

    void go(int c,int sum){
        if(sum>=r) return;
        if(c==n){
            for(int i=0;i<k;++i) {
                if (!gd(i)) return;
            }

            for(int i=0;i<k;++i){
                for(int j=i+1;j<k;++j){
                    if(!ck(i,j)){
                        return;
                    }
                }
            }
            r = sum;
            return;
        }

        for(int i=0;i<k;++i){
            int tmp[] = pos[i].clone();
            int zx = x[c];
            int zy = y[c];

            int prev = area(i);

            pos[i][0] = Math.max(pos[i][0],zy);
            pos[i][1] = Math.min(pos[i][1],zy);

            pos[i][2] = Math.min(pos[i][2],zx);
            pos[i][3] = Math.max(pos[i][3],zx);

            int cur = area(i);

            go(c+1,sum-prev+cur);

            pos[i] = tmp;
        }

    }

    int dx[] = {0,0,1,-1};
    int dy[] = {1,-1,0,0};
    boolean xiao(int mp[][]){
        boolean ok = false;
        boolean mk[][] = new boolean[7][5];
        for(int i=0;i<7;++i){
            for(int j=0;j<5;++j){
                if(mp[i][j]==0) continue;
                int k = j+1;
                int c = mp[i][j];
                while(k<5&&mp[i][k]==c) k++;
                if(k-j>=3){
                    ok = true;
                    for(int u=j;u<k;++u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<5;++i){
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) break;
                int k = j-1;
                int c = mp[i][j];
                while(k>=0&&mp[i][k]==c) k--;
                if(j-k>=3){
                    ok = true;
                    for(int u=j;u>k;--u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<7;++i) {
            for (int j = 0; j < 5; ++j) {
                if (mp[i][j] > 0 && mk[i][j]) {
                    mp[i][j] = 0;
                }
            }
        }
      return ok;
    }

    void luo(int[][] mp){
        for(int i=0;i<5;++i){
            int f = 6;
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) continue;
                mp[i][f] = mp[i][j];f--;
                mp[i][j] = 0;
            }
        }
    }

    void go(int mp[][]){

        while(xiao(mp)){
            luo(mp);
        }

    }

    void sort(int a[]){
        Arrays.sort(a);
    }

    int gcd(int a,int b){
        return b==0?a:gcd(b,a%b);
    }

    void solve() {
//        int n = ni();
//        int mp[][] = new int[7][5];
//        // less than 10;
//
//        for(int i=0;i<5;++i){
//            int x = 6;
//            while(true){
//                int num = ni();
//                if(num==0) break;
//                mp[x][i] = num;
//                x--;
//            }
//        }

            int n = ni();

            int root = ni();

            boolean vis[] = new boolean[n+1];
            vis[root] = true;

            List<Integer> ch[] = new ArrayList[n+1];

            for(int i=1;i<=n;++i){
                ch[i] = new ArrayList<>();
            }
            int cur = root;
        int ma = n;
        if(ma==root){
            ma--;
        }
        for(int i=0;i<n-2;++i){
                int v = ni();
                if(!vis[v]){
                    ch[cur].add(v);
                    vis[v] = true;
                    cur = v;
                    if(v==ma){
                        ma--;
                    }
                }else{
                    while(vis[ma]) ma--;
                    ch[cur].add(ma);
                    vis[ma] = true;
                    ma--;
                    cur = v;
                }
            }
        while(vis[ma]) ma--;
        ch[cur].add(ma);

            init(n);
            for(int i=1;i<=n;++i){
                for(int go:ch[i]){
                    combine(go-1,i-1);
                }
            }
            if(groups==1){
                println(root);
                for(int i=1;i<=n;++i){
                    for(int go:ch[i]){
                        println(go+" "+i);
                    }
                }
            }else{
                println(-1);
            }

    }

    InputStream is;
    PrintWriter out;

    void run() throws Exception {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private char ncc() {
        int b = readByte();
        return (char) b;
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private String nline() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!isSpaceChar(b) || b == ' ') {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[][] nm(int n, int m) {
        char[][] a = new char[n][];
        for (int i = 0; i < n; i++) a[i] = ns(m);
        return a;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private long[] nal(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nl();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    void print(Object obj) {
        out.print(obj);
    }

    void println(Object obj) {
        out.println(obj);
    }

    void println() {
        out.println();
    }

    void printArray(int a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }

    void printArray(long a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }
}


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

// written by luchy0120

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

        new Main().run();
    }

    static int groups = 0;
    static int[] fa;
    static int[] sz;

    static void init(int n) {
        groups = n;
        fa = new int[n];
        for (int i = 1; i < n; ++i) {
            fa[i] = i;
        }
        sz = new int[n];
        Arrays.fill(sz, 1);
    }

    static int root(int p) {
        while (p != fa[p]) {
            fa[p] = fa[fa[p]];
            p = fa[p];
        }
        return p;
    }

    static void combine(int p, int q) {
        int i = root(p);
        int j = root(q);
        if (i == j) {
            return;
        }
        if (sz[i] < sz[j]) {
            fa[i] = j;
            sz[j] += sz[i];
        } else {
            fa[j] = i;
            sz[i] += sz[j];
        }
        groups--;
    }

    int color[],dfn[],low[],stack[],cnt[];
    boolean vis[];
    boolean iscut[];
    int deep,top,n,m,sum,ans;
    List<Integer> g[];

    void tarjan(int u,int fa) {
        int child = 0;
        dfn[u]=++deep;
        low[u]=deep;
        vis[u]=true;
        stack[++top]=u;
        int sz=g[u].size();
        for(int i=0;i<sz;i++) {
            int v =g[u].get(i);
            if(v==fa) continue;
            if(dfn[v]==0) {
                child++;
                tarjan(v,u);
                low[u]=Math.min(low[u],low[v]);
            } else {
                if(vis[v]) {
                    low[u]=Math.min(low[u],low[v]);
                }
            }
        }
        if(fa<0&&child==1){
            iscut[u] =true;
        }

        if(dfn[u]==low[u]) {
            iscut[u] = true;
            color[u]=++sum;
            vis[u]=false;
            while(stack[top]!=u) {
                color[stack[top]]=sum;
                vis[stack[top--]]=false;
            }
            top--;
        }
    }

    int h[],to[],ne[];int ct =0;
    void add(int u,int v){
        u--;v--;
        to[ct] = v;
        ne[ct] = h[u];
        h[u] = ct++;
    }

    void graph(int n,int m){
        h = new int[n];
        Arrays.fill(h,-1);
        ne = new int[2*m];
        to = new int[2*m];
        ct = 0;
    }

    static long mul(long a, long b, long p)
    {
        long res=0,base=a;
        while(b>0)
        {
            if((b&1L)>0)
                res=(res+base)%p;
            base=(base+base)%p;
            b>>=1;
        }
        return res;
    }

    static long mod_pow(long k,long n,long p){
        long res = 1L;
        long temp = (k%p+p)%p;
        while(n!=0L){
            if((n&1L)==1L){
                res = ((res*temp)%p+p)%p;
            }
            temp = ((temp * temp)%p+p)%p;
            n = n>>1L;
        }
        return res%p;
    }
    public static String roundS(double result, int scale){
        String fmt = String.format("%%.%df", scale);
        return String.format(fmt, result);
    }

    int x[];
    int y[];
    int k ;
    int r = 1000000000;
    int[][] pos;

    boolean gd(int i){
        if(pos[i][0]<pos[i][1]) return false;
        if(pos[i][2]>pos[i][3]) return false;
        return true;
    }

    int area(int i){
        if(pos[i][0]<=pos[i][1]) return 0;
        if(pos[i][2]>=pos[i][3]) return 0;
        return (pos[i][0]-pos[i][1])*(pos[i][3]-pos[i][2]);
    }

    boolean in(int i,int y,int x){
        return y<=pos[i][0]&&y>=pos[i][1] && x<=pos[i][3] && x>= pos[i][2];
    }

    boolean ck(int i,int j){
        return !in(i, pos[j][0],pos[j][3]) &&
        !in(i, pos[j][0],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][3]);
    }

    void go(int c,int sum){
        if(sum>=r) return;
        if(c==n){
            for(int i=0;i<k;++i) {
                if (!gd(i)) return;
            }

            for(int i=0;i<k;++i){
                for(int j=i+1;j<k;++j){
                    if(!ck(i,j)){
                        return;
                    }
                }
            }
            r = sum;
            return;
        }

        for(int i=0;i<k;++i){
            int tmp[] = pos[i].clone();
            int zx = x[c];
            int zy = y[c];

            int prev = area(i);

            pos[i][0] = Math.max(pos[i][0],zy);
            pos[i][1] = Math.min(pos[i][1],zy);

            pos[i][2] = Math.min(pos[i][2],zx);
            pos[i][3] = Math.max(pos[i][3],zx);

            int cur = area(i);

            go(c+1,sum-prev+cur);

            pos[i] = tmp;
        }

    }

    int dx[] = {0,0,1,-1};
    int dy[] = {1,-1,0,0};
    boolean xiao(int mp[][]){
        boolean ok = false;
        boolean mk[][] = new boolean[7][5];
        for(int i=0;i<7;++i){
            for(int j=0;j<5;++j){
                if(mp[i][j]==0) continue;
                int k = j+1;
                int c = mp[i][j];
                while(k<5&&mp[i][k]==c) k++;
                if(k-j>=3){
                    ok = true;
                    for(int u=j;u<k;++u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<5;++i){
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) break;
                int k = j-1;
                int c = mp[i][j];
                while(k>=0&&mp[i][k]==c) k--;
                if(j-k>=3){
                    ok = true;
                    for(int u=j;u>k;--u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<7;++i) {
            for (int j = 0; j < 5; ++j) {
                if (mp[i][j] > 0 && mk[i][j]) {
                    mp[i][j] = 0;
                }
            }
        }
      return ok;
    }

    void luo(int[][] mp){
        for(int i=0;i<5;++i){
            int f = 6;
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) continue;
                mp[i][f] = mp[i][j];f--;
                mp[i][j] = 0;
            }
        }
    }

    void go(int mp[][]){

        while(xiao(mp)){
            luo(mp);
        }

    }

    void sort(int a[]){
        Arrays.sort(a);
    }

    int gcd(int a,int b){
        return b==0?a:gcd(b,a%b);
    }

    void solve() {
//        int n = ni();
//        int mp[][] = new int[7][5];
//        // less than 10;
//
//        for(int i=0;i<5;++i){
//            int x = 6;
//            while(true){
//                int num = ni();
//                if(num==0) break;
//                mp[x][i] = num;
//                x--;
//            }
//        }

            int n = ni();

            int root = ni();

            boolean vis[] = new boolean[n+1];
            vis[root] = true;

            List<Integer> ch[] = new ArrayList[n+1];

            for(int i=1;i<=n;++i){
                ch[i] = new ArrayList<>();
            }
            int cur = root;
        int ma = n;
        if(ma==root){
            ma--;
        }
        for(int i=0;i<n-2;++i){
                int v = ni();
                if(!vis[v]){
                    ch[cur].add(v);
                    vis[v] = true;
                    cur = v;
                    if(v==ma){
                        ma--;
                    }
                }else{
                    while(vis[ma]) ma--;
                    ch[cur].add(ma);
                    vis[ma] = true;
                    ma--;
                    cur = v;
                }
            }
        while(vis[ma]) ma--;
        ch[cur].add(ma);

            init(n+1);
            for(int i=1;i<=n;++i){
                for(int go:ch[i]){
                    if(root(go)==root(i)){
                        println(-1); return;
                    }
                    combine(go,i);
                }
            }

                println(root);
                for(int i=1;i<=n;++i){
                    for(int go:ch[i]){
                        println(go+" "+i);
                    }
                }

    }

    InputStream is;
    PrintWriter out;

    void run() throws Exception {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private char ncc() {
        int b = readByte();
        return (char) b;
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private String nline() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!isSpaceChar(b) || b == ' ') {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[][] nm(int n, int m) {
        char[][] a = new char[n][];
        for (int i = 0; i < n; i++) a[i] = ns(m);
        return a;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private long[] nal(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nl();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    void print(Object obj) {
        out.print(obj);
    }

    void println(Object obj) {
        out.println(obj);
    }

    void println() {
        out.println();
    }

    void printArray(int a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }

    void printArray(long a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }
}


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

// written by luchy0120

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

        new Main().run();
    }

    static int groups = 0;
    static int[] fa;
    static int[] sz;

    static void init(int n) {
        groups = n;
        fa = new int[n];
        for (int i = 1; i < n; ++i) {
            fa[i] = i;
        }
        sz = new int[n];
        Arrays.fill(sz, 1);
    }

    static int root(int p) {
        while (p != fa[p]) {
            fa[p] = fa[fa[p]];
            p = fa[p];
        }
        return p;
    }

    static void combine(int p, int q) {
        int i = root(p);
        int j = root(q);
        if (i == j) {
            return;
        }
        if (sz[i] < sz[j]) {
            fa[i] = j;
            sz[j] += sz[i];
        } else {
            fa[j] = i;
            sz[i] += sz[j];
        }
        groups--;
    }

    int color[],dfn[],low[],stack[],cnt[];
    boolean vis[];
    boolean iscut[];
    int deep,top,n,m,sum,ans;
    List<Integer> g[];

    void tarjan(int u,int fa) {
        int child = 0;
        dfn[u]=++deep;
        low[u]=deep;
        vis[u]=true;
        stack[++top]=u;
        int sz=g[u].size();
        for(int i=0;i<sz;i++) {
            int v =g[u].get(i);
            if(v==fa) continue;
            if(dfn[v]==0) {
                child++;
                tarjan(v,u);
                low[u]=Math.min(low[u],low[v]);
            } else {
                if(vis[v]) {
                    low[u]=Math.min(low[u],low[v]);
                }
            }
        }
        if(fa<0&&child==1){
            iscut[u] =true;
        }

        if(dfn[u]==low[u]) {
            iscut[u] = true;
            color[u]=++sum;
            vis[u]=false;
            while(stack[top]!=u) {
                color[stack[top]]=sum;
                vis[stack[top--]]=false;
            }
            top--;
        }
    }

    int h[],to[],ne[];int ct =0;
    void add(int u,int v){
        u--;v--;
        to[ct] = v;
        ne[ct] = h[u];
        h[u] = ct++;
    }

    void graph(int n,int m){
        h = new int[n];
        Arrays.fill(h,-1);
        ne = new int[2*m];
        to = new int[2*m];
        ct = 0;
    }

    static long mul(long a, long b, long p)
    {
        long res=0,base=a;
        while(b>0)
        {
            if((b&1L)>0)
                res=(res+base)%p;
            base=(base+base)%p;
            b>>=1;
        }
        return res;
    }

    static long mod_pow(long k,long n,long p){
        long res = 1L;
        long temp = (k%p+p)%p;
        while(n!=0L){
            if((n&1L)==1L){
                res = ((res*temp)%p+p)%p;
            }
            temp = ((temp * temp)%p+p)%p;
            n = n>>1L;
        }
        return res%p;
    }
    public static String roundS(double result, int scale){
        String fmt = String.format("%%.%df", scale);
        return String.format(fmt, result);
    }

    int x[];
    int y[];
    int k ;
    int r = 1000000000;
    int[][] pos;

    boolean gd(int i){
        if(pos[i][0]<pos[i][1]) return false;
        if(pos[i][2]>pos[i][3]) return false;
        return true;
    }

    int area(int i){
        if(pos[i][0]<=pos[i][1]) return 0;
        if(pos[i][2]>=pos[i][3]) return 0;
        return (pos[i][0]-pos[i][1])*(pos[i][3]-pos[i][2]);
    }

    boolean in(int i,int y,int x){
        return y<=pos[i][0]&&y>=pos[i][1] && x<=pos[i][3] && x>= pos[i][2];
    }

    boolean ck(int i,int j){
        return !in(i, pos[j][0],pos[j][3]) &&
        !in(i, pos[j][0],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][3]);
    }

    void go(int c,int sum){
        if(sum>=r) return;
        if(c==n){
            for(int i=0;i<k;++i) {
                if (!gd(i)) return;
            }

            for(int i=0;i<k;++i){
                for(int j=i+1;j<k;++j){
                    if(!ck(i,j)){
                        return;
                    }
                }
            }
            r = sum;
            return;
        }

        for(int i=0;i<k;++i){
            int tmp[] = pos[i].clone();
            int zx = x[c];
            int zy = y[c];

            int prev = area(i);

            pos[i][0] = Math.max(pos[i][0],zy);
            pos[i][1] = Math.min(pos[i][1],zy);

            pos[i][2] = Math.min(pos[i][2],zx);
            pos[i][3] = Math.max(pos[i][3],zx);

            int cur = area(i);

            go(c+1,sum-prev+cur);

            pos[i] = tmp;
        }

    }

    int dx[] = {0,0,1,-1};
    int dy[] = {1,-1,0,0};
    boolean xiao(int mp[][]){
        boolean ok = false;
        boolean mk[][] = new boolean[7][5];
        for(int i=0;i<7;++i){
            for(int j=0;j<5;++j){
                if(mp[i][j]==0) continue;
                int k = j+1;
                int c = mp[i][j];
                while(k<5&&mp[i][k]==c) k++;
                if(k-j>=3){
                    ok = true;
                    for(int u=j;u<k;++u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<5;++i){
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) break;
                int k = j-1;
                int c = mp[i][j];
                while(k>=0&&mp[i][k]==c) k--;
                if(j-k>=3){
                    ok = true;
                    for(int u=j;u>k;--u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<7;++i) {
            for (int j = 0; j < 5; ++j) {
                if (mp[i][j] > 0 && mk[i][j]) {
                    mp[i][j] = 0;
                }
            }
        }
      return ok;
    }

    void luo(int[][] mp){
        for(int i=0;i<5;++i){
            int f = 6;
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) continue;
                mp[i][f] = mp[i][j];f--;
                mp[i][j] = 0;
            }
        }
    }

    void go(int mp[][]){

        while(xiao(mp)){
            luo(mp);
        }

    }

    void sort(int a[]){
        Arrays.sort(a);
    }

    int gcd(int a,int b){
        return b==0?a:gcd(b,a%b);
    }

    void solve() {
//        int n = ni();
//        int mp[][] = new int[7][5];
//        // less than 10;
//
//        for(int i=0;i<5;++i){
//            int x = 6;
//            while(true){
//                int num = ni();
//                if(num==0) break;
//                mp[x][i] = num;
//                x--;
//            }
//        }

            int n = ni();

            int cur = ni();
            StringBuilder sb  =new StringBuilder();
            sb.append(cur+"\n");
            boolean vis[] = new boolean[n+1];
            vis[cur] = true;

        int ma = n;
        if(ma==cur){
            ma--;
        }
        for(int i=0;i<n-2;++i){
                int v = ni();
                if(!vis[v]){
                    sb.append(cur+" "+v+"\n");
                    vis[v] = true;
                    cur = v;
                    if(v==ma){
                        ma--;
                    }
                }else{
                    while(vis[ma]) ma--;
                    sb.append(cur+" "+ma+"\n");
                    vis[ma] = true;
                    ma--;
                    cur = v;
                }
            }
        if(vis[ma]) ma--;
        sb.append(cur+" "+ma+"\n");
        println(sb);

//            init(n+1);
//            for(int i=1;i<=n;++i){
//                for(int go:ch[i]){
//                    if(root(go)==root(i)){
//                        println(-1); return;
//                    }
//                    combine(go,i);
//                }
//            }

//                println(root);
//                for(int i=1;i<=n;++i){
//                    for(int go:ch[i]){
//                        println(go+" "+i);
//                    }
//                }
//

    }

    InputStream is;
    PrintWriter out;

    void run() throws Exception {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private char ncc() {
        int b = readByte();
        return (char) b;
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private String nline() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!isSpaceChar(b) || b == ' ') {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[][] nm(int n, int m) {
        char[][] a = new char[n][];
        for (int i = 0; i < n; i++) a[i] = ns(m);
        return a;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private long[] nal(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nl();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    void print(Object obj) {
        out.print(obj);
    }

    void println(Object obj) {
        out.println(obj);
    }

    void println() {
        out.println();
    }

    void printArray(int a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }

    void printArray(long a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }
}


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

// written by luchy0120

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

        new Main().run();
    }

    static int groups = 0;
    static int[] fa;
    static int[] sz;

    static void init(int n) {
        groups = n;
        fa = new int[n];
        for (int i = 1; i < n; ++i) {
            fa[i] = i;
        }
        sz = new int[n];
        Arrays.fill(sz, 1);
    }

    static int root(int p) {
        while (p != fa[p]) {
            fa[p] = fa[fa[p]];
            p = fa[p];
        }
        return p;
    }

    static void combine(int p, int q) {
        int i = root(p);
        int j = root(q);
        if (i == j) {
            return;
        }
        if (sz[i] < sz[j]) {
            fa[i] = j;
            sz[j] += sz[i];
        } else {
            fa[j] = i;
            sz[i] += sz[j];
        }
        groups--;
    }

    int color[],dfn[],low[],stack[],cnt[];
    boolean vis[];
    boolean iscut[];
    int deep,top,n,m,sum,ans;
    List<Integer> g[];

    void tarjan(int u,int fa) {
        int child = 0;
        dfn[u]=++deep;
        low[u]=deep;
        vis[u]=true;
        stack[++top]=u;
        int sz=g[u].size();
        for(int i=0;i<sz;i++) {
            int v =g[u].get(i);
            if(v==fa) continue;
            if(dfn[v]==0) {
                child++;
                tarjan(v,u);
                low[u]=Math.min(low[u],low[v]);
            } else {
                if(vis[v]) {
                    low[u]=Math.min(low[u],low[v]);
                }
            }
        }
        if(fa<0&&child==1){
            iscut[u] =true;
        }

        if(dfn[u]==low[u]) {
            iscut[u] = true;
            color[u]=++sum;
            vis[u]=false;
            while(stack[top]!=u) {
                color[stack[top]]=sum;
                vis[stack[top--]]=false;
            }
            top--;
        }
    }

    int h[],to[],ne[];int ct =0;
    void add(int u,int v){
        u--;v--;
        to[ct] = v;
        ne[ct] = h[u];
        h[u] = ct++;
    }

    void graph(int n,int m){
        h = new int[n];
        Arrays.fill(h,-1);
        ne = new int[2*m];
        to = new int[2*m];
        ct = 0;
    }

    static long mul(long a, long b, long p)
    {
        long res=0,base=a;
        while(b>0)
        {
            if((b&1L)>0)
                res=(res+base)%p;
            base=(base+base)%p;
            b>>=1;
        }
        return res;
    }

    static long mod_pow(long k,long n,long p){
        long res = 1L;
        long temp = (k%p+p)%p;
        while(n!=0L){
            if((n&1L)==1L){
                res = ((res*temp)%p+p)%p;
            }
            temp = ((temp * temp)%p+p)%p;
            n = n>>1L;
        }
        return res%p;
    }
    public static String roundS(double result, int scale){
        String fmt = String.format("%%.%df", scale);
        return String.format(fmt, result);
    }

    int x[];
    int y[];
    int k ;
    int r = 1000000000;
    int[][] pos;

    boolean gd(int i){
        if(pos[i][0]<pos[i][1]) return false;
        if(pos[i][2]>pos[i][3]) return false;
        return true;
    }

    int area(int i){
        if(pos[i][0]<=pos[i][1]) return 0;
        if(pos[i][2]>=pos[i][3]) return 0;
        return (pos[i][0]-pos[i][1])*(pos[i][3]-pos[i][2]);
    }

    boolean in(int i,int y,int x){
        return y<=pos[i][0]&&y>=pos[i][1] && x<=pos[i][3] && x>= pos[i][2];
    }

    boolean ck(int i,int j){
        return !in(i, pos[j][0],pos[j][3]) &&
        !in(i, pos[j][0],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][3]);
    }

    void go(int c,int sum){
        if(sum>=r) return;
        if(c==n){
            for(int i=0;i<k;++i) {
                if (!gd(i)) return;
            }

            for(int i=0;i<k;++i){
                for(int j=i+1;j<k;++j){
                    if(!ck(i,j)){
                        return;
                    }
                }
            }
            r = sum;
            return;
        }

        for(int i=0;i<k;++i){
            int tmp[] = pos[i].clone();
            int zx = x[c];
            int zy = y[c];

            int prev = area(i);

            pos[i][0] = Math.max(pos[i][0],zy);
            pos[i][1] = Math.min(pos[i][1],zy);

            pos[i][2] = Math.min(pos[i][2],zx);
            pos[i][3] = Math.max(pos[i][3],zx);

            int cur = area(i);

            go(c+1,sum-prev+cur);

            pos[i] = tmp;
        }

    }

    int dx[] = {0,0,1,-1};
    int dy[] = {1,-1,0,0};
    boolean xiao(int mp[][]){
        boolean ok = false;
        boolean mk[][] = new boolean[7][5];
        for(int i=0;i<7;++i){
            for(int j=0;j<5;++j){
                if(mp[i][j]==0) continue;
                int k = j+1;
                int c = mp[i][j];
                while(k<5&&mp[i][k]==c) k++;
                if(k-j>=3){
                    ok = true;
                    for(int u=j;u<k;++u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<5;++i){
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) break;
                int k = j-1;
                int c = mp[i][j];
                while(k>=0&&mp[i][k]==c) k--;
                if(j-k>=3){
                    ok = true;
                    for(int u=j;u>k;--u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<7;++i) {
            for (int j = 0; j < 5; ++j) {
                if (mp[i][j] > 0 && mk[i][j]) {
                    mp[i][j] = 0;
                }
            }
        }
      return ok;
    }

    void luo(int[][] mp){
        for(int i=0;i<5;++i){
            int f = 6;
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) continue;
                mp[i][f] = mp[i][j];f--;
                mp[i][j] = 0;
            }
        }
    }

    void go(int mp[][]){

        while(xiao(mp)){
            luo(mp);
        }

    }

    void sort(int a[]){
        Arrays.sort(a);
    }

    int gcd(int a,int b){
        return b==0?a:gcd(b,a%b);
    }

    void solve() {
//        int n = ni();
//        int mp[][] = new int[7][5];
//        // less than 10;
//
//        for(int i=0;i<5;++i){
//            int x = 6;
//            while(true){
//                int num = ni();
//                if(num==0) break;
//                mp[x][i] = num;
//                x--;
//            }
//        }

            int n = ni();

            int root = ni();

            boolean vis[] = new boolean[n+1];
            vis[root] = true;

            List<Integer> ch[] = new ArrayList[n+1];

            for(int i=1;i<=n;++i){
                ch[i] = new ArrayList<>();
            }
            int cur = root;
        int ma = n;
        if(ma==root){
            ma--;
        }
        for(int i=0;i<n-2;++i){
                int v = ni();
                if(!vis[v]){
                    ch[cur].add(v);
                    vis[v] = true;
                    cur = v;
                    if(v==ma){
                        ma--;
                    }
                }else{
                    while(ma>=1&&vis[ma]) ma--;
                    ch[cur].add(ma);
                    vis[ma] = true;
                    ma--;
                    cur = v;
                }
            }
        while(ma>=1&&vis[ma]) ma--;
        if(ma>=1){
            ch[cur].add(ma);
        }

            init(n);
            for(int i=1;i<=n;++i){
                for(int go:ch[i]){
                    combine(go-1,i-1);
                }
            }
            if(groups==1){
                println(root);
                for(int i=1;i<=n;++i){
                    for(int go:ch[i]){
                        println(go+" "+i);
                    }
                }
            }else{
                println(-1);
            }

    }

    InputStream is;
    PrintWriter out;

    void run() throws Exception {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private char ncc() {
        int b = readByte();
        return (char) b;
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private String nline() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!isSpaceChar(b) || b == ' ') {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[][] nm(int n, int m) {
        char[][] a = new char[n][];
        for (int i = 0; i < n; i++) a[i] = ns(m);
        return a;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private long[] nal(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nl();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    void print(Object obj) {
        out.print(obj);
    }

    void println(Object obj) {
        out.println(obj);
    }

    void println() {
        out.println();
    }

    void printArray(int a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }

    void printArray(long a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }
}