/*
 
@author
_      _          _                 _      _
\\    // /\    | | \  |     |    /\ \\    //     
 \\  // /__\   | |_/  |_____|   /__\ \\  //
  \\// /    \  | | \  |     |  /    \ \\//
   \/ /      \ | |_/  |     | /      \ \/
@ Indian Institute of Technology Bhilai
*/
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define fr(i,start,end, inc) for(ll i=(start); i<(end); i+=inc)
#define rf(i,end,start, inc) for(ll i=(start-1); i>=(end); i-=inc)
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<n; i++)
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define pl pair<ll, ll>
#define pi pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define alla(arr,n) arr, arr+n
#define fsync ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll maxx =  1e9+7;

bool compare(const pl &a, const pl &b){
    return a.fi<b.fi || (a.fi==b.fi && a.se<b.se);
}
ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll inv(ll n, ll p){
    return power(n,p-2, p);
}
inline vector<ll> allinv(ll n, ll p){
    vector<ll> arr(n);
    arr[1]=1;
    fr(i,2,n,1){
        arr[i] = (p - (p/i)*arr[p%i]%p)%p;
    }
    return arr;
}
vector<ll> inline allncr(ll n, ll p){
    vector<ll> nci(n+1);
    nci[0]=1;
    nci[n]=1;
    vector<ll> v = allinv(n,p);
    fr(i,1,n,1){
        nci[i]=(nci[i-1]*(n-i-1))%p;
    }
    return nci;
}
ll max3(ll a, ll b, ll c){
    return max(max(a,b),c);
}

bool inline isPrime(ll n) { 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}

void prt(int i){   
    i ? cout << "YES\n" : cout << "NO\n" ;
}

template<class T>
void printv(T &v){
    ll n = v.size();
    rep(i,n)
        cout << v[i] << " ";
    cout << "\n";
}

bool check(ll a, ll b, ll c){
    if(a==-1 && b==-1 && c==-1)
        return true;
    return false;
}
int main(){
    fsync
    ll test=1;
    // cin >> test;
    while(test--){
        ll n,m,a,b;
        cin >> n >> m;
        if(n==1 && m==0){
            cout << 0 << "\n";
            continue;
        }
        vector<ll> v(3,-1);
        bool poss=true;
        rep(i,m){
            cin >> a >> b;
            if(v[a-1]==-1){
                if(a-1 == 0 && b==0 && n>1){
                    poss=false;
                }
                v[a-1]=b;
            }
            else{
                if(v[a-1] != b){
                    poss=false;
                }
            }
        }
        if(poss){
            if(v[0]==-1)
                v[0]=1;
            if(n>1 && v[1]==-1)
                v[1]=0;
            if(n>2 && v[2]==-1)
                v[2]=0;
            ll ans=0;
            ll x=1;
            rep(i,n){
                ans += v[n-i-1]*x;
                x *= 10;
            }
            cout << ans << "\n";
        }
        else
            cout << -1 << "\n";   
    }

}

Measured memory_bytes: 256