#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const long long INF = 1LL << 60;
using vll = vector<long long>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pair<long long, long long> = pair<long long, long long>;
using vc = vector<char>;
using vvc = vector<vc>;
long long dx[4] = {0, 1, 0, -1};
long long dy[4] = {1, 0, -1, 0};
int main() {
  long long n, m;
  cin >> n >> m;
  vll s(m), c(m);
  for (long long i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  long long k;
  if (n == 1) k = 10;
  if (n == 2) k = 100;
  if (n == 3) k = 1000;
  for (long long i = 0; i < (k); i++) {
    long long kk = 0;
    long long keta;
    keta = (int)(to_string(i)).size();
    for (long long j = 0; j < (m); j++) {
      if (keta < s[j]) break;
      long long cu = n - s[j];
      if (cu == 0) {
        long long f = i % 10;
        if (f == c[j]) kk++;
      } else if (cu == 1) {
        long long f = i / 10;
        f %= 10;
        if (f == c[j]) kk++;
      } else {
        long long f = i / 100;
        if (f == c[j]) kk++;
      }
    }
    if (kk == m) {
      cout << (i) << endl;
      return 0;
    }
  }
  cout << (-1) << endl;
}
