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