#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
int kurai(int x) {
  int ret = 1;
  while (x >= 10) {
    x /= 10;
    ret++;
  }
  return ret;
}
int baibai(int x) {
  int ret = 1;
  for (int i = 0; i < (int)(x); i++) ret *= 10;
  return ret;
}
int beki(int x, int y) {
  x %= baibai(y);
  x /= baibai(y - 1);
  return x;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> data(m);
  for (int i = 0; i < (int)(m); i++) cin >> data[i].first >> data[i].second;
  int ans = 0;
  for (int i = 1; i < 1000; i++) {
    if (kurai(i) != n) continue;
    int check = 0;
    for (int j = 0; j < (int)(m); j++) {
      if (beki(i, n - data[j].first + 1) == data[j].second) check++;
    }
    if (check == m) {
      cout << i << "\n";
      ans++;
      break;
    }
  }
  if (ans == 0) cout << -1 << "\n";
}
