#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m + 1);
  vector<char> c(m + 1);
  string kekka = "100";
  if (n == 1) {
    string kekka = "0";
  }
  if (n == 2) {
    string kekka = "10";
  }
  if (n == 3) {
    string kekka = "100";
  }
  for (size_t i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
    int a = s.at(i);
    if (a > n) {
      kekka = "-1";
    }
    for (size_t j = 0; j < i; j++) {
      if (a == s.at(j) && c.at(i) != c.at(j)) {
        kekka = "-1";
      }
    }
  }
  if (kekka != "-1") {
    for (size_t i = 0; i < m; i++) {
      kekka.at(s.at(i) - 1) = c.at(i);
    }
  }
  if (kekka != "-1") {
    if (kekka.at(n - 1) == '0') {
      kekka = "-1";
    }
  }
  cout << kekka << endl;
}
