#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
template <typename T>
T lcm(T a, T b) {
  return a / __gcd(a, b) * b;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> sc(m);
  for (int i = 0; i < (int)n; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    sc[i] = {s, c};
  }
  for (int i = 0; i < pow(10, n); i++) {
    str tmp = to_string(i);
    if (tmp.size() != n) continue;
    bool is_ok = true;
    for (int j = 0; j < (int)m; j++) {
      if (tmp[sc[j].first] != '0' + sc[j].second) {
        is_ok = false;
      }
    }
    if (is_ok) {
      cout << tmp << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
