#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long 
#define PI 3.14159265358979323846
#define INF 10000000000
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;

int main() {
	ll N, M, ans = 0;
	cin >> N >> M;
	vector<ll> s(M), c(M);
	rep(x, M) cin >> s[x] >> c[x];
	vector<ll> keta(N);
	rep(j, M) {
		if (s[j] > N) {
			cout << "-1" << endl;
			return 0;
		}
		if (keta[N - s[j]] == 0 || keta[N - s[j]] == c[j]) {
			keta[N - s[j]] = c[j];
		}
		else{
			cout << "-1" << endl;
			return 0;
		}
	}
	if (N > 1 && keta[N - 1] == 0) {
		cout << "-1" << endl;
		return 0;
	}
	if (N > 2 && keta[0] == 0) keta = 1;
	ll J = 1;
	rep(i, N){
		ans += J * keta[i];
	    J *= 10;
    }
cout << ans << endl;

return 0;
}
