#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  int wrong = -1;
  int keta[3];
  for (int i = 0; i < (3); i++) keta[i] = -1;
  for (int i = 0; i < (m); i++) {
    for (int j = 0; j < (n); j++) {
      if ((c[i] != keta[s[i] - 1]) && (keta[s[i] - 1] > -1)) {
        cout << wrong << endl;
        return 0;
      }
    }
    keta[s[i] - 1] = c[i];
  }
  if (keta[n - 1] < 0) {
    cout << wrong << endl;
    return 0;
  }
  for (int i = 0; i < (n); i++) {
    if (keta[i] < 0) {
      keta[i] = 0;
    }
  }
  int res = 0;
  for (int i = 0; i < (n); i++) res += keta[i] * pow(10, n - i - 1);
  cout << res << endl;
  return 0;
}
