#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
		tree_order_statistics_node_update> ordered_set;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 2e5 + 9, M = 1e4 + 9, OO = (int) 2e9 + 1;
const long long MOD = 998244353, INF = 1e18 + 9;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(0);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

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

char num[4];
int n, m;

int main() {
//	INPUT();
	OUTPUT();
	cin >> n >> m;
	clr(num, '?');
	char s;
	int id;
	bool can = 1;
	for (int i = 0; i < m; i++) {
		cin >> id >> s;
		id--;
		if (num[id] == '?') {
			num[id] = s;
		} else {
			if (num[id] != s)
				can = 0;
		}
	}
	string nn = "";
	for (int i = 0; i < n; i++) {
		if (num[i] == '?') {
			(i == 0 ? num[i] = '1' : num[i] = '0');
		}
		nn += num[i];
	}
	nn = to_string(stoi(nn));
	if (sz(nn) < n)
		can = 0;
	if (!can)
		cout << -1;
	else
		cout << nn;

	return 0;

}
