#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  std::cin >> n >> m;
  map<int, char> sc;
  for (int cnt = 0; cnt < m; cnt++) {
    int idx;
    char str;
    std::cin >> idx >> str;
    if (sc.find(idx - 1) != sc.end()) {
      if (sc.at(idx - 1) != str) {
        std::cout << -1 << '\n';
        return 0;
      }
    }
    sc.insert(make_pair(idx - 1, str));
  }
  string ans = "-1";
  for (int num = 999; num >= 0; num--) {
    string s = to_string(num);
    bool ok_flag = true;
    for (auto idx = sc.begin(); idx != sc.end(); idx++) {
      try {
        if (s.at(idx->first) != idx->second || s.size() != n) {
          ok_flag = false;
        }
      } catch (out_of_range e) {
        ok_flag = false;
      }
    }
    if (ok_flag) ans = s;
  }
  std::cout << ans << '\n';
  return 0;
}
