#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  std::string s(n, '*');
  for (int i = 0; i < m; ++i) {
    int id;
    char c;
    std::cin >> id >> c;
    --id;
    if (s[id] == '*' or (s[id] == c)) {
      s[id] = c;
    } else {
      return puts("-1") * 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (s[i] != '0') continue;
    bool flag = (i != 0);
    for (int j = i - 1; j >= 0; --j) {
      if (s[j] != '*' and s[j] != '0') flag = true;
    }
    if (not flag) return puts("-1") * 0;
  }
  for (auto& c : s)
    if (c == '*') c = '0';
  while (s.front() == '0') s.erase(s.begin());
  std::cout << s << '\n';
}
