#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> nums(N + 1, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (s > N) {
      cout << -1 << endl;
      return 0;
    }
    if (nums[s] != -1 && nums[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    nums[s] = c;
  }
  bool valid = false;
  for (int i = 1; i <= N; i++) {
    if (nums[i] != -1 && nums[i] != 0) {
      valid = true;
    }
  }
  if (!valid) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= N; i++) {
    if (nums[i] == -1) {
      cout << 0;
    } else {
      cout << nums[i];
    }
  }
  cout << endl;
  return 0;
}
