#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, y, z;
  cin >> n >> m;
  vector<int> x(n, 10);
  for (int i = 0; i < m; i++) {
    cin >> y >> z;
    if (y == 1 && z == 0) {
      cout << -1 << endl;
      exit(0);
    }
    if (x[y - 1] != 10 && x[y - 1] != z) {
      cout << -1 << endl;
      exit(0);
    }
    x[y - 1] = z;
  }
  if (x[0] == 10) {
    if (n != 1) {
      x[0] = 1;
    } else {
      x[0] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << x[i] % 10;
  }
  cout << endl;
}
