#include <bits/stdc++.h>
using namespace std;
int n, m, a[10] = {-1}, b[10];
int s, c;
int main() {
  cin >> n >> m;
  int p = m;
  for (int i = 0; i <= 9; i++) a[i] = -1;
  while (m--) {
    cin >> s >> c;
    if (a[s] == -1 || a[s] == c)
      a[s] = c;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[1] == 0) {
    if (p == 1) {
      cout << -1 << endl;
      return 0;
    }
    a[1] = 1;
  }
  for (int i = 1; i <= p; i++) {
    if (a[i] == -1) a[i] = 0;
    cout << a[i];
  }
  cout << endl;
  return 0;
}
