#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define endl "\n"
#define mod 1000000007
#define INF 1e18
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define w(x) int x; cin >> x; while (x--)

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void rwf()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int xpowery(int x, int y)
{
	int ans = 1;
	while (y)
	{
		if (y & 1)
			ans = (ans * x) % mod;
		x = (x * x) % mod;
		y = y / 2;
	}
	return ans;
}

int32_t main()
{
	IOS;
	//rwf();

	int n, m;
	cin >> n >> m;

	int dig[n + 1];

	for (int i = 1; i <= n; i++)
		dig[i] = -1;

	int x, y;
	bool ok = true;

	for (int i = 0; i < m; i++)
	{
		cin >> x >> y;

		if (dig[x] != -1 && dig[x] != y)
		{
			ok = false;
		}
		else
		{
			dig[x] = y;
		}
	}

	if (!ok)
	{
		cout << "-1";
	}
	else
	{
		if (dig[1] == 0 && n != 1)
			cout << "-1";
		else
		{
			for (int i = 1; i <= n; i++)
			{
				if (i == 1 && dig[i] == -1)
					cout << "1";
				else
				{
					if (dig[i] != -1)
						cout << dig[i];
					else
						cout << "0";
				}
			}
		}
	}

	return 0;
}