#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, m; cin >> n >> m; 
    vector<int> s(m), c(m);
    rep(i, m) cin >> s[i] >> c[i]; s[i]--;

    int mn, mx;
    if(n==1)mn=0, mx=9;
    if(n==2)mn=10, mx=99;
    if(n==3)mn=100, mx=999;

    int res = -1;
    for(int i=mn; i<=mx; i++){
	bool fg = true;
        string num = to_string(i);
	rep(j, m){
	    if(c[j] != num[s[j]]){fg = false; break;}
	}
        if(fg){res = i; break;}
    }
    cout << res << ln;
}