#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define INF 100000000
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int n, m;
  cin >> n >> m;
  vector<P> p(m);
  rep(i,m) cin >> p[i].first >> p[i].second;
  
  //0から999まで全探索して条件を満たすか確かめる
  rep(x,1000){
  	int nx = x/10;
  	vector<int> d(x%10);
  	d[0] = 1;
  	while(nx){
  		d.push_back(nx%10);
  		nx /= 10;
  	}
  	reverse(d.begin(), d.end());
  	bool can = true;
  	if(n != d.size()) contine;
  	rep(i,m){
  		if(d[p[i].first-1] != p[i].second) can = false;
  	}
  	if(can) cout << x << endl;
  	return 0;
  }
  cout << -1 << endl;
  return 0;
}

