#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>>s[m];
  rep(i,m) {
    cin>> s[i].first >> s[i].second;
  }
  rep(x,1000){
    int nx=x/10;
    vector<int>d(1,x%10);
    while(nx){
      d.push_back(nx%10);
      nx/=10;
    }
    reverse(d.begin(),d.end());
    if(d[s[i].first]==s[i].second){
      cout<<x<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}
