#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  memset(a, -1, sizeof a);
  int s, c;
  bool ok = true;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (a[s - 1] != -1 && a[s - 1] != c) {
      ok = false;
    }
    a[s - 1] = c;
  }
  if (n > 1 && (a[0] == -1 || a[0] == 0) && !ok)
    puts("-1");
  else {
    for (int i = 0; i < n; i++) {
      a[i] += (a[i] == -1);
      cout << a[i];
    }
    cout << "\n";
  }
}
