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