#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n, 0);
  bool f = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (vec.at(s - 1) == 0 || vec.at(s - 1) == c) {
      vec.at(s - 1) = c;
      if (n == 3) {
        if (vec.at(0) == 0) {
          f = false;
        }
      }
      if (n == 2) {
        if (vec.at(1) == 0) {
          f = false;
        }
      }
    } else {
      f = false;
      break;
    }
  }
  if (f) {
    for (auto& e : vec) {
      cout << e;
    }
  } else {
    cout << -1;
  }
  cout << endl;
}
