#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long i, j, t, k;
  long long a[4] = {0};
  bool ch[4] = {false};
  while (m--) {
    cin >> t >> k;
    if (ch[t] == true && a[t] != k) {
      cout << -1 << endl;
      return 0;
    } else {
      a[t] = k;
      ch[t] = true;
    }
  }
  if (a[1] == 0 && n != 1) {
    cout << -1 << endl;
  } else {
    for (i = 1; i <= n; i++) {
      cout << a[i];
    }
    cout << endl;
  }
  return 0;
}
