//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;

long long nCm(long long n, long long m) {
	long long ans = 1;
	for (long long i = 1; i <= m; i++) {
		ans = ans * n / i;
		n--;
	}
	return ans;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int>s(M), c(M);
	for (int i = 0; i < M; i++) {
		cin >> s[i] >> c[i];
	}
	if (N == 1) {
		for (int i = 0; i <= 9; i++) {
			int check = 0;
			string t = to_string(i);
			for (int j = 0; j < M; j++) {
				if (n == c[j]) {
					check++;
				}
			}
			if (check == M) {
				cout << i << endl;
				return 0;
			}
		}
		cout << -1 << endl;
	}
	else if (N == 2) {
		for (int i = 10; i <= 99; i++) {
			int check = 0;
			string t = to_string(i);
			for (int j = 0; j < M; j++) {
				int n = stoi(t.substr(s[j] - 1, 1));
				if (n == c[j]) {
					check++;
				}
			}
			if (check == M) {
				cout << i << endl;
				return 0;
			}
		}
		cout << -1 << endl;
	}
	else {
		for (int i = 100; i <= 999; i++) {
			int check = 0;
			string t = to_string(i);
			for (int j = 0; j < M; j++) {
				int n = stoi(t.substr(s[j] - 1, 1));
				if (n == c[j]) {
					check++;
				}
			}
			if (check == M) {
				cout << i << endl;
				return 0;
			}
		}
		cout << -1 << endl;
	}
}
