#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::lower_bound;
using std::make_pair;
using std::pair;
using std::stack;
using std::string;
using std::unordered_set;
using std::upper_bound;
using std::vector;
int main(int argc, char* argv[]) {
  int m, n;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  vector<int> r(n, -1);
  for (int i = 0; i < m; ++i) {
    if (r[s[i] - 1] == -1 || r[s[i] - 1] == c[i]) {
      r[s[i] - 1] = c[i];
    } else {
      cout << -1;
      return 0;
    }
  }
  if (r[0] == 0) {
    cout << -1;
    return 0;
  }
  if (r[0] == -1) {
    r[0] = n == 1 ? 0 : 1;
  }
  for (int i = 1; i < m; ++i) {
    if (r[i] == -1) {
      r[i] = 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << r[i];
  }
  return 0;
}
