#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  multimap<int, int> s;
  vector<int> answer(3);
  if (n == 3) {
    answer = {1, 0, 0};
  } else if (n == 2) {
    answer = {0, 1, 0};
  } else {
    answer = {0, 0, 0};
  }
  for (int var = 0; var < m; ++var) {
    int s1, s2;
    cin >> s1 >> s2;
    s.emplace(s1, s2);
    if (s1 == 1 && s2 == 0 && n == 1) {
      cout << -1 << endl;
      return 0;
    }
    auto p = s.equal_range(s1);
    for (auto it = p.first; it != p.second; ++it) {
      if (s2 != it->second) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (auto &num : s) {
    answer[(num.first) - 1] = num.second;
  }
  cout << 100 * answer[0] + 10 * answer[1] + answer[2] << endl;
  return 0;
}
