#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, h = 0, k = 0;
  cin >> N >> M;
  vector<int> a(10, 0);
  vector<bool> b(10, 0);
  bool x = 0;
  for (int i = 0; i < M; i++) {
    int x, z;
    cin >> x >> z;
    if (z == 0) h = x;
    k = max(k, x);
    if (b[x - 1] == 1 && a[x - 1] != z) {
      cout << -1 << endl;
      return 0;
    }
    a[x - 1] = z;
    b[x - 1] = 1;
  }
  if (N == N - h + 1)
    cout << -1 << endl;
  else {
    for (int i = 0; i < k; i++) cout << a[i];
  }
}
