#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
bool keta_check(int a, vector<int> &s, vector<int> &c, int m) {
  vector<int> keta_num;
  while (1) {
    if (a == 0) break;
    keta_num.push_back(a % 10);
    a /= 10;
  }
  reverse(keta_num.begin(), keta_num.end());
  for (int i = 0; i < (m); ++i) {
    if (keta_num[s[i]] == c[i]) {
      continue;
    }
    return false;
  }
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); ++i) {
    int tmp_s;
    cin >> tmp_s >> c[i];
    --tmp_s;
    s[i] = tmp_s;
  }
  int min_num = 1;
  for (int i = 0; i < (n - 1); ++i) {
    min_num *= 10;
  }
  int max_num = 1;
  for (int i = 0; i < (n); ++i) {
    max_num *= 10;
  }
  for (int i = min_num; i < max_num; ++i) {
    if (keta_check(i, s, c, m)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
