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