#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 (id != n - 1 && c == '0') return puts("-1") * 0;
    if (s[id] == '*' or (s[id] == c)) {
      s[id] = c;
    } else {
      return puts("-1") * 0;
    }
  }
  for (auto& c : s)
    if (c == '*') c = '0';
  while (s.front() == '0') s.erase(s.begin());
  std::cout << s << '\n';
}
