#include <bits/stdc++.h>
int a() {
  int a, b = 0;
  std::cin >> a >> b;
  struct Condition {
    int digit;
    int num;
  };
  std::vector<Condition> input;
  for (int i = 0; i < b; i++) {
    Condition temp;
    std::cin >> temp.digit >> temp.num;
    input.push_back(temp);
  }
  std::vector<int> ans(a, -1);
  bool noAns = false;
  for (int i = 0; i < b; i++) {
    auto myValue = input[i];
    if (a < myValue.digit) {
      noAns = true;
      break;
    }
    if (myValue.digit == 1 && myValue.num == 0 && 2 <= a) {
      noAns = true;
      break;
    }
    int index = myValue.digit - 1;
    if (ans[index] == -1) {
      ans[index] = myValue.num;
    } else {
      if (ans[index] != myValue.num) {
        noAns = true;
        break;
      }
    }
  }
  int ansVal = -1;
  if (!noAns) {
    ansVal = 0;
    for (int i = 0; i < a; i++) {
      if (ans[i] == -1) {
        if (i == 0) {
          ans[i] = 1;
        } else {
          continue;
        }
      }
      ansVal += ans[i] * std::pow(10, a - i - 1);
    }
  }
  std::cout << ansVal;
  return 0;
}
int main(int argc, const char* argv[]) {
  a();
  return 0;
}
