#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n,m;
  cin >> n >>m;
  int s[m];
  int c[m];
  int ans[n]={};
  rep(i,m){
    cin >> s[i];
    cin >> c[i];
    if(ans[s[i]-1]==0||ans[s[i]-1]==c[i]){
      ans[s[i]-1]=c[i];
    }
    else{
      cout << "-1" << endl;
      return 0;
    }
    
  }
  if(ans[0]==0){
    cout << "-1" <<endl;
    return 0;
  }
  rep(i,n){
    cout << ans[i];
  }
  cout << endl;
  return 0;
}