#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  std::cin >> n >> m;
  vector<string> sc(m, string("10"));
  for (int cnt = 0; cnt < m; cnt++) {
    int idx;
    string c;
    std::cin >> idx;
    std::cin >> c;
    if (sc[idx - 1] == "10") {
      sc[idx - 1] = c;
    } else if (sc[idx - 1] != c) {
      std::cout << "-1" << '\n';
      return 0;
    }
  }
  string s = "";
  for (int idx = 0; idx < n; idx++) {
    if (sc[idx] == "10") {
      if (idx == 0) {
        s += "1";
      } else {
        s += "0";
      }
    } else {
      s += sc[idx];
    }
  }
  int x = stoi(s);
  string xx = to_string(x);
  if (n != xx.size()) {
    std::cout << -1 << '\n';
    return 0;
  }
  std::cout << s << '\n';
  return 0;
}
