#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[3][3] = {0}, b = 1, bb, cc, dd, ee, ff, c = 0, x = 0, max = 0,
            dig = 0, ans = 0;
  int n = 0, k = 0, nc = 0, m = 0, out = -1;
  long long left = 0, right = 0, ii[3] = {0}, ic = 0;
  string s, t, u, now;
  vector<double> z, zz, count, countc;
  vector<string> ss;
  vector<long long int>::iterator position;
  bool q = false;
  vector<vector<bool>> counter(3, vector<bool>(3, false));
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> b >> c;
    z.push_back(b);
    zz.push_back(c);
  }
  bb = z.at(0);
  if (m >= 2) cc = z.at(1);
  if (m >= 3) dd = z.at(2);
  if (m >= 4) ee = z.at(3);
  if (m >= 5) ff = z.at(4);
  if (n == 1) {
    left = 0;
    right = 10;
  }
  if (n == 2) {
    left = 10;
    right = 100;
  }
  if (n == 3) {
    left = 100;
    right = 1000;
  }
  for (int i = left; i < right; i++) {
    ic = i;
    ii[0] = ic % 10;
    ic /= 10;
    ii[1] = ic % 10;
    ic /= 10;
    ii[2] = ic % 10;
    if (m == 1 && ii[n - bb] == zz.at(0) ||
        m == 2 && ii[n - bb] == zz.at(0) && ii[n - cc] == zz.at(1) ||
        m == 3 && ii[n - bb] == zz.at(0) && ii[n - cc] == zz.at(1) &&
            ii[n - dd] == zz.at(2) ||
        m == 4 && ii[n - bb] == zz.at(0) && ii[n - cc] == zz.at(1) &&
            ii[n - dd] == zz.at(2) && ii[n - ee] == zz.at(3) ||
        m == 5 && ii[n - bb] == zz.at(0) && ii[n - cc] == zz.at(1) &&
            ii[n - dd] == zz.at(2) && ii[n - ee] == zz.at(3) &&
            ii[n - ff] == zz.at(4)) {
      cout << i << endl;
      break;
    }
    if (i == right - 1) cout << out << endl;
  }
  return 0;
}
