#include <utility>
#include <vector>
#include <iostream>
#include <cstdlib>
#include<bits/stdc++.h>
#include <limits>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <stdio.h>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
ull gcd(ull a, ull b){return b? gcd(b, a%b):a;}
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;

	int s[M] = {0};
	char c[M] = {0};

	for(int i = 0; i < M; i++){
		cin >> s[i] >> c[i];
	}

	int output = -1;
	for(int i = 0; i < pow(10, N); i++){
		if(N==2 && i < 10){
			continue;
		}else if (N ==3 && i < 100){
			continue;
		}
		char numStr[N];
		sprintf(numStr, "%d", i);
		
		bool correct = true;
		for(int j = 0; j < M; j++){
			if(numStr[s[j]-1]!=c[j]){
				correct = false;
				break;
			}
		}
		if(correct){
			output = i;
			break;
		}
	}

    cout <<output<< endl;
    return 0;
}
