#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> d;
  for (int i = 0; i < m; i++) {
    int b, c;
    cin >> b >> c;
    if (d.count(b) && d[b] != c || b > n) {
      cout << -1 << endl;
      return 0;
    }
    if (d.count(b) && d[b] == c) {
    }
    d[b] = c;
  }
  if (!(d.count(1))) d[1] = 1;
  if (n != 1 && d[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    cout << d[i];
  }
  cout << endl;
}
