#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T=ll>
using v =vector<T>;
template<typename T=ll>
using vv = vector<v<T>>;
template<typename T=ll,typename U=ll> using p = pair<T,U>;
const ll INF = (ll)1e9;
const ll MOD = INF+7;
template<typename T> T chmin(T &a,T b){a=min(a,b);}
template<typename T> T chmax(T &a,T b){a=max(a,b);}

struct modint
{
    ll a;
    modint():a(0){}
    modint(ll t){
        a=t%MOD;
        if(a<0) a+=MOD;
    }
    //operator long long() const{return a;}
    bool operator==(const modint & x)const{return a==x.a;}
    bool operator!=(const modint & x)const{return a!=x.a;}
    modint operator-() const {return modint(a?(MOD-a):0);}
    modint operator~() const {return modint(MOD -2);}
    modint operator+(const modint &x) const{return modint(*this)+=x;}
    modint operator-(const modint &x) const{return modint(*this)-=x;}
    modint operator*(const modint &x) const{return modint(*this)*=x;}
    modint operator/(const modint &x) const{return modint(*this)/=x;}
    modint &operator+=(const modint &x){
        a+= x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint &operator-=(const modint &x){
        a-= x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    
    modint &operator*=(const modint &x){
        a=a*x.a %MOD;
        return *this;
    }
    modint &operator/=(const modint &x){
        a=a*(~x).a %MOD;
        return *this;
    }

    friend ostream &operator<<(ostream &os,const modint &x){
        return os << x.a;
    }

    friend istream &operator>>(istream &is,modint &x){
        ll t;
        x=modint(t);
        return is;
    }

    modint pow(ll x)const{
        modint ret = 1,tmp=a;
        for(;x;tmp*=tmp,x>>=1){
            if(x&1) ret*=tmp;
        }
        return ret;
    }

};

modint nCr(int n,int r){
    modint ans=1;
    for(int i=1;i<=r;i++) ans*=modint(n-i+1)/modint(i);
    return ans;
}


void a(){
    ll n; cin >> n;
    cout << (n-1)/2 + 1;
}

void b(){
    auto a = vv<>(3,v<>(3,0));
    rep(i,3)rep(j,3){
        cin >> a[i][j];
    }

    ll n; cin >> n;
    auto b=v<>(n,0);
    rep(i,n) cin >> b[i];

    rep(i,3)
        rep(j,3){
            rep(k,n){
                if(a[i][j]==b[k]) a[i][j]=-1;
            }
        }
    
    rep(i,3){
        bool col=true;
        bool row=true;
        bool dyl=true;
        bool dyu=true;
        rep(j,3){
            if(a[i][j]>=0)col=false;
            if(a[j][i]>=0)row=false;
            if(a[j][j]>=0)dyl=false;
            if(a[2-j][j]>=0)dyu=false;
        }
        if(col||row||dyl||dyu){
            cout << "Yes"<<endl;
            return ;
        }
    }

    cout << "No"<<endl;
}
class C{
    string check;
    ll n,m;

    ll dfs(string ss){
        if(n!=1&&ss.front()=='0') return INF;
        if(ss.size()>n) return INF;
        if(ss.size()==n){
            rep(i,n){
              if(check[i]=='@') continue;
              if(check[i]!=ss[i]) {
                  return INF;
              }
            }
            return stoi(ss);
        }

        ll ans=INF;
        for(char c='0';c<='9';c++){
            chmin(ans,dfs(ss+c));
        }
        return ans;
    }
    public:
    C(){
        cin >> n >> m;
        check = string(n,'@');
        rep(j,m){
                int s;
                char c;
                cin >>s >> c;
                s--;
                if(check[s]=='@'||check[s]==c){
                	check[s]=c;
          			continue;  
                }
          		cout << -1 << endl;
                return ;
            }
      	ll ans = dfs("");
      	cout << (ans>=INF?-1:ans);
   }
};

int main(){
    C();
    return 0;
}

Measured memory_bytes: 256