#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;


int main(void){
    int n,m;
    cin >> n >> m;
    int s[m],c[m];
    REP(i,m) cin >> s[i] >> c[i];
    int ans[n]={0};
    REP(i,m){
        if(ans[s[i]-1]==0 || ans[s[i]-1]==c[i]){
            ans[s[i]-1]=c[i];
        }
        else if(s[i]-1==0 && c[i]==0){
            cout << -1;
            return 0;
        }
        else{
            cout << -1;
            return 0;
        }
    }
    if(s[0]==0){
        cout << -1;
    }else{
        REP(i,m)printf("%d",ans[i]);
    }
    return 0;
}