#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n, m;
	cin >> n >> m;
	
	vector<set<int>> s(n);
	
	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		x--;
		s[x].insert(y);
		
		if(n != 1 && x == 0 && y == 0){
			cout << -1 << endl;
			return 0;
		}
		
		if(s[x].size() > 1){
			cout << -1 << endl;
			return 0;
		}
	}
	
	vector<int> ans(n, -1);
	
	for(int i = 0; i < n; i++)
		for(auto &x : s[i])
			ans[i] = x;
	
	for(int i = 0; i < n; i++)
		if(ans[i] == -1)
			ans[i] = 0;
	
	for(int i = 0; i < n; i++)
		cout << ans[i];
	cout << endl;

	return 0;
}
