#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int size;
  int rules;
  cin >> size;
  cin >> rules;
  vector<string> digits(size, "0");
  for (int i = 0; i < rules; i++) {
    int digit;
    string rule;
    cin >> digit;
    cin >> rule;
    if (digit == 1 && rule == "0" && size > 1) {
      cout << -1;
      break;
    }
    if ((digits[digit - 1] != "0" && digits[digit - 1] == rule) ||
        digits[digit - 1] == "0") {
      digits[digit - 1] = rule;
    } else {
      cout << -1;
      return 0;
    }
  }
  string str = "";
  for (int i = 0; i < size; i++) {
    if (i == 0) {
      if (digits[i] == "0" && size > 1)
        str += "1";
      else {
        str += digits[i];
      }
    } else
      str += digits[i];
  }
  cout << str;
  return 0;
}
