#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  bool flag = false;
  long long ans = -1, sum = 0;
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > op(m);
  for (int i = 0, _i = (m); i < _i; ++i) {
    int s, c;
    cin >> s >> c;
    pair<int, int> em = {s, c};
    op[i] = em;
  }
  int lim = (int)pow(10, n) + 10;
  for (int i = 0, _i = (lim); i < _i; ++i) {
    string num = to_string(i);
    bool jud = true;
    for (int j = 0, _i = (m); j < _i; ++j) {
      if (op[j].first > num.length() || num.length() != n) {
        jud = false;
        break;
      }
      if (num[op[j].first - 1] != '0' + op[j].second) {
        jud = false;
        break;
      }
    }
    if (jud) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
