#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
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() {
    int N,M;
    cin >> N >> M;
    int s[M],c[M];
    rep(i,M){
        cin >> s[i] >> c[i];
    }

    int k[N]={0};
    rep(i,M){
        if((k[s[i]-1] != c[i]) && (k[s[i]-1] != 0)){
            cout << "-1" << endl;
            return 0;
        }
        if(k[s[i]-1] == 0){
            k[s[i]-1] = c[i];
        }
    }

    if(k[0]==0){
        cout << "-1" << endl;
        return 0;
    }

    rep(i,N){
        cout << k[i];
    }
    cout << endl;

    return 0;
}