#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)


int main() {
    int n,m;
    cin>>n>>m;
    int s[m], c[m];
    int a[n][2] = {0};
    rep(i,m){
        cin>>s[i]>>c[i];
        if(a[s[i]-1][1]==0){
            if(a[s[i]-1][0]<c[i]){
                a[s[i]-1][0] = c[i];
                a[s[i]][1] = 1;
            }
        }else{
            cout<<-1<<endl;
            return 0;
        }
    }

    int ans = 0;
    rep(i,n) ans += a[n-i-1][0]*pow(10,i);

    if(ans < pow(10,n-1))cout<<-1<<endl;
    else cout<<ans<<endl;

    return 0;
}
