#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define in(a) cin >> a;
#define out(a) cout << a << endl;
#define inV(A) REP(i,A.size()) in(A[i]);
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-----------------------------------
int main(){
    init();
    ll n,m;
    in(n);in(m);
    vl s(m);
    vl c(m);
    map<int,int> A;
    map<int,int> B;
    REP(i,m){
        cin >> s[i] >> c[i];
        A[s[i]]=1;
        if(A[s[i]]!=1) B[s[i]]=c[i];
    }
    if(n==1){
        FOR(i,1,10){
            int f=1;
            REP(j,m){
                if(i!=c[j]) f=0;  
            }
            if(f){
                cout << i << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }else if(n==2){
        FOR(i,10,100){
            int f=1;
            REP(j,m){
                ll x;
                if(s[j]==1) x= i/10;
                else x= i%10;
                if(x!=c[j]) f=0;  
            }
            if(f){
                cout << i << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }else{
        FOR(i,100,1000){
            int f=1;
            REP(j,m){
                ll x;
                if(s[j]==1) x= i/100;
                else if(s[j]==2) x= (i/10)%10;
                else x= i%10;
                if(x!=c[j]) f=0;  
            }
            if(f){
                cout << i << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }
 
}