#include <utility>
#include <vector>
#include <iostream>
#include <cstdlib>
#include<bits/stdc++.h>
#include <limits>
#include <set>
#include <map>
#include <string>
#include <sstream>
#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 ans[N] = {0};
	if(N != 1){
		ans[0] = 1;
	}
	bool invalid = false;
	REP(i, M){
		int s, c;
		cin >> s >> c;
		if(s-1 == 0 && c ==0){
			invalid = true;
		}
		if(ans[s-1] == 0 || (ans[s-1] == 1 && s-1 == 0) || ans[s-1] == c){
			ans[s-1] = c;
		}else{
			invalid = true;
		}
	}
	int output=ans[0];
	if(invalid){
		output = -1;
	}else{
		for(int i = 1; i < N; i++){
			output *=10;
			output += ans[i];
		}
	}

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