#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a[3];
  cin >> n >> m;
  for (long long i = 0; i < 3; i++) {
    a[i] = -1;
  }
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    x--;
    if (a[x] != -1 && a[x] != y) {
      cout << -1;
      return 0;
    }
    a[x] = y;
  }
  for (long long i = 0; i < n; i++) {
    if (a[0] == 0 && n != 1) {
      cout << -1;
      return 0;
    }
    if (a[i] == -1) {
      if (i != 0) {
        cout << 0;
      } else {
        cout << 1;
      }
    } else {
      cout << a[i];
    }
  }
  return 0;
}
