#include <bits/stdc++.h>
using namespace std;
long long MAX = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> m;
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    if (m.find(s) == m.end()) {
      m[s] = c;
    } else {
      if (m[s] != c) {
        cout << -1 << endl;
        return -1;
      }
    }
  }
  vector<int> ans(3, 0);
  for (auto kv : m) {
    if (kv.first == 1) {
      if (kv.second == 0) {
        cout << -1 << endl;
        return -1;
      } else
        ans[0] = kv.second;
    }
    if (kv.first == 2) {
      ans[1] = kv.second;
    }
    if (kv.first == 3) {
      ans[2] = kv.second;
    }
  }
  cout << 100 * ans[0] + 10 * ans[1] + ans[2] << endl;
}
