#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in(),m=in();
    string ans(n,'\0');
    for(int i=0;i<m;++i){
        ll s=in()-1;
        char c='0'+in();
        if(ans[s]=='\0'){
            ans[s]=c;
        }else if(ans[s]!=c){
            cout<<-1<<endl;
            return 0;
        }
    }
    if(ans[0]=='\0'||ans[0]=='0'){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=0;i<n;++i){
        cout<<(ans[i]=='\0'?'0':ans[i]);
    }
    cout<<endl;
}
