#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> nums;
  for (int i = 0; i < m; i++) {
    int digit, nth;
    cin >> digit >> nth;
    if (nums.count(digit) && nums.at(digit) < nth) {
      continue;
    }
    nums[digit] = nth;
  }
  int ans = -1;
  for (int i = 1; i <= m; i++) {
    if (nums.count(i)) {
      ans = ans == -1 ? nums.at(i) : ans * 10 + nums.at(i);
    } else {
      ans *= 10;
    }
  }
  if (ans <= 0 || ans < pow(10, n - 1) || ans > pow(10, n) || nums.at(1) == 0) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
