#include <bits/stdc++.h>
using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int n, m;
	cin >> n >> m;
	vector<int> ans(n, 0);
	bool flag = true;
	int cnt = 0;
	for (int i = 0; i < m; ++i){
		int s, c;
		cin >> s >> c;
		if (ans[s - 1] != 0 && ans[s - 1] != c){
			flag = false;
		}
		else{
			if (c > 0) cnt++;
			ans[s - 1] = c;
		}
	}
	if (!flag || !cnt){
		cout << -1;
		return 0;
	}
	for (int i = 0; i < n; ++i){
		cout << ans[i];
	}
	return 0;
}

