#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m;
  bool flag = true;
  cin >> n >> m;
  vector<int> a(n,0);
  for(int i = 0; i < m; i++) {
    int s,c;
    cin >> s >> c;
    if(a[s-1] != 0 && a[s-1] != c) {flag = false; break;}
    if(s == 1 && c == 0 && n != 1) {
      cout << "-1" << endl;
      return 0;
    }
    a[s-1] = c;
  }
  if(a[0] == 0 && n != 1) a[0] = 1;
  if(flag) {
    for(int i = 0; i < n; i++) cout << a[i];
    cout << endl;
  }
  else cout << "-1" << endl;
  return 0;
}