#include<bits/stdc++.h>
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int s[M], c[M];
    rep(i, M) {
        cin >> s[i];
        cin >> c[i];
    }

    int d[4];
    rep(i, 4){
        d[i] = -1;
    }
    rep(i, M){
        if (d[s[i]] == -1) {
            d[s[i]] = c[i];
        } else {
            if (d[s[i]] != c[i]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    ll ans = 0;

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

    rep(i, N) {
        if (i == N-1) {
            if (d[N-i] != -1) {
                ans += pow(10,i)*d[N-i];
            } else {
                ans += pow(10,i);
            }
        } else {
            if(d[N-i] != -1) {
                ans += pow(10,i)*d[N-i];
            }
        }
    }
    cout << ans << endl;

}
