#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)



int main() {
	int n,m;
	cin >> n >> m;

	vector<int> d(n, -1);

	rep(i, m) {
		int s, c;
		cin >> s >> c;
		s--;
		if (d[s] == -1) {
			d[s] = c;
		} else if (d[s] != c) {
			cout << -1 << endl;
			return 0; 
		}
	}
	if (d[0] == 0) {
		cout << -1 << endl;
		return 0;
	}
	if (d[0] == -1) {
		d[0] = 1; 
	}
	if (all_zero) {
		cout << -1 << endl;
		return 0;
	}
	
	int ans = 0;
	rep(i, n) {
		ans *= 10;
		if (d[i] != -1) {
			ans += d[i];
		}
		//cout << "i:" << i << ":" << ans << endl;
	}
	cout << ans << endl;

	return 0;
}