#include"bits/stdc++.h"

using namespace std;

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define PI 3.141592653589793
#define scanstr(s) cin>>ws; getline(cin,s);

void solve()
{
	int n,m;
	cin>>n>>m;
	int low,high;
	if(n==1) low=0, high=9;
	if(n==2) low=10, high=99;
	if(n==3) low=100, high=1000;
	int a[2*m];
	for(int i=0;i<2*m;i++) cin>>a[i];
	for(low=0;low<high;low++)
	{
		int x=low;
		string s;
		while(x)
		{
			int k=x%10;
			x/=10;
			char c='0'+k;
			s+=c;
		}
		reverse(s.begin(),s.end());
		bool ok=true;
		for(int i=0;i<2*m;i+=2)
		{
			int x=a[i];
			x--;
			int k=a[i+1];
			char c='0'+k;
			if(c!=s[x])
			{
				ok=false;
				break;
			}
		}
		if(s.size()!=n && s[0]=='0') ok=false;
		if(ok)
		{
			cout<<low<<nl;
			return ;
		}
	}
	cout<<-1<<nl;
	return ;
}