#include <bits/stdc++.h>
using namespace std;
int main() {
  int num_digit, num_input, digit_substituted, num_substituted;
  cin >> num_digit >> num_input;
  if (num_input == 0) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> num_output(num_digit);
  vector<bool> judge_substituted(num_digit);
  vector<int> digit_const(num_input), num_const(num_input);
  for (int i = 0; i < num_input; i++) {
    cin >> digit_const.at(i) >> num_const.at(i);
  }
  for (int i = 0; i < num_input; i++) {
    if (digit_const.at(i) == 1 && num_const.at(i) == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < num_digit; i++) {
    judge_substituted.at(i) = false;
    num_output.at(i) = 0;
  }
  for (int i = 0; i < num_input; i++) {
    digit_substituted = digit_const.at(i) - 1;
    num_substituted = num_const.at(i);
    if (!judge_substituted.at(digit_substituted)) {
      num_output.at(digit_substituted) = num_substituted;
      judge_substituted.at(digit_substituted) = true;
    } else if (num_output.at(digit_substituted) != num_substituted) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (!judge_substituted.at(0)) {
    num_output.at(0) = 1;
  }
  for (int i = 0; i < num_digit; i++) {
    cout << num_output.at(i);
  }
  cout << endl;
  return 0;
}
