#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const long long mod = pow(10, 9) + 7;
const long long INF = pow(2, 31) - 1;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  long long lc = (a / g) * b;
  return lc;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > p(m);
  for (int i = 0; i < (m); i++) {
    cin >> p[i].first >> p[i].second;
  }
  for (int x = 0; x < (1000); x++) {
    int keta = 1;
    int nx = x / 10;
    vector<int> d(1, x % 10);
    while (nx) {
      keta++;
      d.push_back(nx % 10);
      nx /= 10;
    }
    if (keta != n) continue;
    bool ok = true;
    reverse(d.begin(), d.end());
    for (int i = 0; i < (n); i++) {
      if (d[p[i].first - 1] != p[i].second) ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
