#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> s(M), c(M), _s(M);
    REP(i,0,M) {
        cin >> s[i] >> c[i];
        _s[i] = s[i];
    }

    vector<ll> num(N, 0);

    ll D;
    sort(ALL(_s));
    D = _s[M-1];

    bool f = true;
    REP(i,1,M){
        REP(j,0,i){
            if(s[i] == s[j] && c[i] != c[j]){
                f = false;
            }
        }
    }
    REP(i,0,M){
        if(N != 1 && s[i] == 1 && c[i] == 0){
            f = false;
        }
    }

    if (f) {
        if(D > N) _PR("-1");
        else {
            REP(i,0,M) {
                num[N-s[i]] = c[i];
            }
            if(N != 1 && num[N-1] == 0) num[N-1] = 1;
            for(ll i=N-1; i>=0; --i;) cout << num[i];
            cout << endl;
        }
    }
    else _PR("-1");
    

    return 0;
}

/*



*/