#include <bits/stdc++.h>
using namespace std;
using intl = int64_t;
using vi = vector<intl>;
using vvi = vector<vi>;
using pi = pair<intl, intl>;
using vpi = vector<pi>;
using si = set<intl>;
using vsi = vector<si>;
using mii = map<intl, intl>;
using vmii = vector<mii>;
vector<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vector<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  intl N, M;
  cin >> N >> M;
  if (M == 0 && N == 1) {
    cout << "0";
    return 0;
  }
  if (M == 0 && N != 1) {
    cout << "-1";
    return 0;
  }
  vi s(M), c(M);
  for (intl ii = 0, nn = (intl)(s.size()); ii < nn; ii++) {
    cin >> (s).at(ii);
    cin >> (c).at(ii);
  };
  intl ans = -1;
  for (intl i = 0, nn = (intl)(1000); i < nn; ++i) {
    string I = to_string(i);
    bool OK = 1;
    for (intl j = 0, nn = (intl)(M); j < nn; ++j) {
      if (I.size() < s[j]) {
        OK = 0;
        break;
      }
      if (I.at(s[j] - 1) != '0' + c[j]) {
        OK = 0;
        break;
      }
      if (I.size() != N) {
        OK = 0;
        break;
      }
    }
    if (OK) {
      ans = i;
      break;
    }
  }
  cout << ans;
}
