#include "bits/stdc++.h"
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    fastio;
    ll n=0,m=0;
    cin>>n>>m;
    ll ar[n+1]={0};
    bool f=true;
    bool seen=false;
    for(ll i=0;i<m;++i){
        ll pos,dig;
        cin>>pos>>dig;
        if(pos==1) seen=true;
        if(ar[pos]!=0 and dig!=ar[pos])
            f=false;
        ar[pos]=dig;

    }
    if(n>=2 and ar[1]==0 and seen) f=false;
    if(!seen) ar[1]=1;
    if(f)
        for(ll i=1;i<=n;++i) cout<<ar[i];
    else
        cout<<"-1";
}
