#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;


int main(){
    int N;cin >> N;
    vector<int> a(N,-1);
    int m;cin >> m;
    rep(mi,m){
        int s,c;cin >> s >> c;s--;
        if(a[s]==-1){
            a[s] = c;
        }else{
            if(a[s]!=c){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    if(a[0]==0){
        if(N==1) continue;
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<N;i++){
        if(a[i]==-1){
            if(i==0) cout << 1;
            else cout << 0;
        }else{
            cout << a[i];
        }
    }
    cout << endl;
}