#include <bits/stdc++.h>
std::vector<int> split(int x) {
  if (x == 0) return {0};
  std::vector<int> ans;
  while (x) ans.push_back(x % 10), x /= 10;
  std::reverse(ans.begin(), ans.end());
  return ans;
}
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::pair<int, int>> condition;
  for (int i = 0; i < m; ++i)
    std::cin >> condition[i].first >> condition[i].second;
  for (int ans = 0; ans <= 999; ++ans) {
    auto res = split(ans);
    if (res.size() != n) continue;
    bool flag = true;
    for (int i = 0; i < m; ++i)
      if (res[condition[i].first - 1] != condition[i].second) flag = false;
    if (!flag) continue;
    std::cout << ans << "\n";
    return 0;
  }
  std::cout << -1 << "\n";
}
