#include <bits/stdc++.h>
using namespace std;
int n, m;
int s[10], c[10];
int main() {
  cin >> n >> m;
  ;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) s[i]--;
  for (int i = 0;; i++) {
    string now = to_string(i);
    if (now.size() > n) {
      cout << -1 << endl;
      return 0;
    }
    if (now.size() != n) continue;
    bool f = 1;
    for (int j = 0; j < n; j++) f &= ((now[s[j]] - '0') == c[j]);
    if (f) {
      cout << now << endl;
      return 0;
    }
  }
  return 0;
}
