#include <bits/stdc++.h>
using namespace std;
bool kaibun(string s) {
  size_t len = s.length();
  for (int i = 0; i < len / 2; i++) {
    if (s[i] != s[len - i - 1]) return false;
  }
  return true;
}
int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  map<int, int> cond;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    auto ret = cond.insert(std::make_pair(a, b));
    if (ret.second == false && cond[a] != b) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (N == 1) {
    if (cond.count(2)) {
      cout << "-1" << endl;
      return 0;
    }
    if (cond.count(3)) {
      cout << "-1" << endl;
      return 0;
    }
    ans = cond[1];
  } else if (N == 2) {
    if (cond[1] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (cond.count(3)) {
      cout << "-1" << endl;
      return 0;
    }
    ans = cond[1] * 10 + cond[2];
    if (ans < 10) ans += 10;
  } else if (N == 3) {
    if (cond[1] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    ans = cond[1] * 100 + cond[2] * 10 + cond[3];
    if (ans < 100) ans += 100;
  }
  cout << ans << endl;
  return 0;
}
