#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  vector<int> v;
  int tmp1, tmp2;
  int k[5] = {99, 99, 99, 99, 99};
  int count = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> tmp1 >> tmp2;
    tmp1--;
    if (k[tmp1] == 99) {
      k[tmp1] = tmp2;
    } else if (k[tmp1] == tmp2) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (n == 1 && tmp2 == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (k[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (k[0] == 99 && i == 0) {
      cout << 1;
    } else if (k[i] == 99) {
      cout << 0;
    } else {
      cout << k[i];
    }
  }
  return 0;
}
