#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);


int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>s(m), c(m);
	rep(i, m) {
		cin >> s[i] >> c[i];
	}
	rep(i, 1000) {
		vector<int>d(1, i % 10);
		bool flag = true;
		int keta = 1;
		int res = i/10;
		while (res > 0) {
			keta++;
			d.push_back(res % 10);
			res /= 10;
		}
		if (keta != n)continue;
		reverse(d.begin(), d.end());
		rep(j, m) {
			if (S[s[j] - 1] != c[j])flag=false;
		}
		if (flag) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}
