#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n, -1);
  if (n >= 2) vec[0] = 1;
  for (int i = (0); i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    if (s > n) {
      cout << -1 << endl;
      return 0;
    }
    if (n > 1 && s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (vec[s - 1] == c || vec[s - 1] < 0) {
      vec[s - 1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = (0); i < (n); ++i) {
    if (vec[i] < 0) {
      cout << 0;
    } else {
      cout << vec[i];
    }
  }
  cout << endl;
  return 0;
}
