#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
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;
}
template <class T>
void println(T a) {
  if (cout.precision() != 12) cout << setprecision(12);
  cout << a << endl;
}
signed main(void) {
  int n, m;
  cin >> n >> m;
  vpint sc(m);
  for (int((i)) = (0), TemPNuM = (int)(((sc).size())); ((i)) < TemPNuM; ++((i)))
    cin >> sc[i].first >> sc[i].second;
  for (int(i) = ((int)pow(10, n - 1)), TemPNuM = (int)((int)pow(10, n));
       (i) < TemPNuM; ++(i)) {
    bool p = true;
    for (auto &(pair) : (sc)) {
      int k = n - pair.first, c = pair.second;
      int t = i;
      for (int((i)) = (0), TemPNuM = (int)((k)); ((i)) < TemPNuM; ++((i)))
        t /= 10;
      p &= c == t % 10;
    }
    if (p) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
