#include <bits/stdc++.h>
using namespace std;
vector<int> digit(int n) {
  vector<int> ans;
  while (1 == 1) {
    ans.push_back(n % 10);
    n /= 10;
    if (n == 0) break;
  }
  return ans;
}
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];
  bool judge = true;
  vector<int> ii;
  int start;
  if (m == 0) {
    start = 0;
  } else {
    start = pow(10, n - 1);
  }
  for (int i = start; i < pow(10, n); i++) {
    ii = digit(i);
    for (int j = 0; j < (m); j++) {
      if (ii[ii.size() - s[j]] != c[j]) judge = false;
    }
    if (judge) {
      cout << i << endl;
      return 0;
    }
    judge = true;
  }
  cout << -1 << endl;
}
