#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int N = 1e5+10;
int a[N],b[N];
int val[N];
int main(){
    int n,m;
    cin >> n >> m;
    int ok = 1;
    for(int i=1;i<=n;++i)  val[i] = -1;
    for(int i=1;i<=m;++i){
        cin >> a[i] >> b[i];
        if(val[a[i]] == -1 || val[a[i]]==b[i]) val[a[i]] = b[i];
        else ok = 0;
    }
    if(val[1] == 0 && n!=1) ok = 0;
    if(!ok){
        cout << "-1\n";
    }
    else{
        if(n==1){
            cout << val[1]==-1?0:val[1] << '\n';
            return 0;
        }

        if(val[1]==-1)  cout << 1;
        else cout << val[1];
        for(int i=2;i<=n;++i){
            if(val[i]!=-1)  cout << val[i];
            else cout << 0 ;
        }
        cout << '\n';
    }
    return 0;
}