#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (size_t i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int a = 1;
  for (size_t i = 0; i < n - 1; i++) {
    a *= 10;
  }
  int min = a;
  a--;
  int i = 1;
  while (i == 1) {
    a++;
    int tf = 0;
    string aa = to_string(a);
    for (size_t i = 0; i < m; i++) {
      if (aa[s[i] - 1] != to_string(c[i])[0]) {
        tf = 1;
      }
    }
    if (tf == 0) {
      i = 0;
    }
    if (a >= min * 10) {
      i = 2;
    }
  }
  if (i == 0) {
    cout << a << endl;
  }
  if (i == 2) {
    cout << "-1" << endl;
  }
  return 0;
}
