#include <bits/stdc++.h>
using namespace std;
int digit(int n) {
  if (n < 10) {
    return 1;
  }
  return digit(n / 10) + 1;
}
string int_to_string(int n) {
  string res = "";
  while (n) {
    char tmp = (n % 10) + '0';
    res = tmp + res;
    n /= 10;
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  for (int i = 0; i < (1000); i++) {
    if (n != digit(i)) {
      continue;
    }
    bool flag = true;
    for (int j = 0; j < (m); j++) {
      string st_num = int_to_string(i);
      if (st_num[s[j] - 1] - '0' != c[j]) {
        flag = false;
      }
    }
    if (flag) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return (0);
}
