#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
  int N,M;
  cin >> N >> M;
  int flg = 0;
  int ans[N] = {0};
  vector<int> s(M),c(M);
  REP(i,M) {
    cin >> s[i] >> c[i];
    ans[s[i]-1] = c[i];
  }
  
  
  REP(i,M) {
    if(ans[s[i]-1] != c[i]) flg = 1;
  }
  
  if(ans[0] == 0) flg = 1;
  if(flg==1) { 
    cout << "-1" << endl;
  } else {
    REP(i,N) {
      cout << ans[i];
    }
  }
  cout << endl;
  

  return 0;
}
