#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> s;
  vector<long long> c;
  for (long long i = 0; i < M; i++) {
    long long ss, cc;
    cin >> ss >> cc;
    s.push_back(ss);
    c.push_back(cc);
  }
  long long ans = -1;
  for (long long i = 702; i <= 702; i++) {
    string num = to_string(i);
    bool ok = true;
    if (num.length() != N) continue;
    for (long long j = 0; j < M; j++) {
      if (num.at(s.at(j) - 1) - '0' != c.at(j)) {
        ok = false;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
