#include <bits/stdc++.h>
using namespace std;
int n, m;
int s[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
int main() {
  bool f = true;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    if (s[a] != b && s[a] == -1)
      s[a] = b;
    else if (s[a] == b)
      ;
    else
      f = false;
  }
  if (!f) {
    cout << -1 << endl;
    return 0;
  }
  for (int num = pow(10, n - 1); num < pow(10, n); num++) {
    string pr = to_string(num);
    bool f1 = true;
    for (int i = 0; i < n; i++) {
      if (s[i] == -1)
        ;
      else if (pr[i] == '0' + s[i])
        ;
      else
        f1 = false;
    }
    if (f1) {
      cout << num << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
