#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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) {
		bool ok = true;
		rep(j, m) {
			if((i/(int)pow(10, n-s[j]))%10 != c[i]) {
				ok = false;
				break;
			}
		}
		if(ok) {
			cout << i << endl;
			return 0;
		}
	}
	out << -1 << endl;
	
	return 0;
}