#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> s(M), c(M);
  for (int i=0; i<M; i++) {
    cin >> s[i] >> c[i];
  }
  
  vector<int> ans(N, -1);
  for (int i=0; i<M; i++) {
    ans[s[i]-1] = c[i];
  }
  
  for (int i=0; i<M; i++) {
    for (int j=i+1; j<M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  
  if (N != 1 && ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  
  for (int i=0; i<N; i++) {
    if (ans[i] == -1) {
      cout << i==0?1:0;
    } else {
      cout << ans[i];
    }
  }
  cout << endl;
  return 0;
}