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

#define int long long

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m;
	int s, c;

	cin >> n >> m;
	int a[n + 1] = {};
	
	for (int i = 0; i < m; ++i)
	{
		cin >> s >> c;

		if (a[s] == 0 || a[s] == c)
			a[s] = c;
		else
		{
			cout << -1;
			return 0;
		}
	}

	if (a[1] == 0 && n != 1)
	{
		cout << -1 << endl;
		return 0;
	}
	
	for (int i = 0; i < n; ++i)
	{
		cout << a[i + 1];
	}
	cout << endl;
	return 0; 
 }