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