#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll powll(ll a, ll n) {
  if (n == 0) {
    return 1;
  }
  return powll(a, n - 1) * a;
}
ll number(ll num, ll keta) {
  return (num % powll(10, keta)) / powll(10, keta - 1);
}
int main() {
  ll i, j, k;
  ll n, m, s[10], c[10], num = -1;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  if (n == 1) {
    for (i = 0; i < 9; i++) {
      for (j = 0; j < m; j++) {
        ll see = n - s[j] + 1;
        if (see <= 0) {
          break;
        }
        if (number(i, see) != c[j]) {
          break;
        }
        if (j == m - 1) {
          cout << i << endl;
          return 0;
        }
      }
    }
  }
  for (i = powll(10, n - 1); i < powll(10, n); i++) {
    for (j = 0; j < m; j++) {
      ll see = n - s[j] + 1;
      if (see <= 0) {
        break;
      }
      if (number(i, see) != c[j]) {
        break;
      }
      if (j == m - 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << num << endl;
}
