#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, s, c, ans, k;
  cin >> n >> m;
  int a[n];
  for (i = 0; i < n; i++) {
    a[i] = -1;
  }
  for (i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if (a[s] != -1 && a[s] != c) {
      cout << "-1";
      return 0;
    }
    a[s] = c;
  }
  if (n == 1 && m == 0) {
    cout << "0";
    return 0;
  }
  if (n > 1 && a[0] == 0) {
    cout << "-1";
    return 0;
  }
  if (a[0] == -1) {
    a[i] = 1;
  }
  k = 0;
  for (i = 0; i < n; i++) {
    a[i] = max(k, a[i]);
  }
  for (i = 0; i < n; i++) {
    cout << a[i];
  }
  return 0;
}
