#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)

//int a[1001][1001] //aise global me hi

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//memset can initialize to 0 or -1 ONLY //memset(str, 't', sizeof(str)); // string
//memset(a, 0, sizeof(a));  //1D array    // memset(a,0,sizeof(a[0][0])*n*n); //2D array
// set.insert(),find()    // sort(v.begin(),v.end(),compare)

void solve()
{
    int n,ma;cin>>n>>ma;
   unordered_map<int,int> m;
    while(ma--)
    {
int a,b;cin>>a>>b;
if(m.count(a)>0) if(m[a]!=b) {cout<<"-1";return;}
m[a]=b;
	}

	string s="";

	if(n>1) 
	{
		if(m[1]==0) {cout<<"-1";return;}
	}

	for(int i=1;i<=n;i++)
	{
		if(m.count(i)==0) s=s+"0";
		else s=s+(char)(48+m[i]);
	}


	if(s[0]=='0')
		s[0]='1';
	cout<<s;
    
}


int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
    {
    
    solve();
    
    }

}