//omajinai c++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#include <map>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
constexpr auto mod = 1000000007;
using namespace std;
int main(void) {

	int n, m;
	cin >> n >> m;
	vector<int> s(m);
	vector<int> c(m);
	rep(i, m) {
		cin >> s[i] >> c[i];
	}
	vector<int> a(n);
	rep(i, n) {
		a[i] = -1;
	}
	int flag = 0;
	rep(i, n) {
		if (s[i] == 1 && c[i] == 0) {
			flag = -1;
			break;
		}
	}
	rep(i, n) {
		if (a[s[i]] == -1) {
			a[s[i]] = c[i];
		}
		else {
			if (a[s[i]] != c[i]) {
				flag = -1;
				break;
			}
		}
	}

	if (flag == -1) {
		cout << -1;
	}

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