#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> nums[m];
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    nums[i] = pair<int, int>(s, c);
  }
  int min = 1;
  if (n == 0) {
    min = 0;
  } else {
    for (int i = 0; i < (n - 1); ++i) min = min * 10;
  }
  int max = 9;
  for (int i = 0; i < (n - 1); ++i) max = max * 10;
  int mid = 0;
  auto c = [&](int num) {
    for (int i = 0; i < (m); ++i) {
      int t = num;
      int a = 1;
      int d = (n - nums[i].first);
      for (int j = 0; j < (d); ++j) a = a * 10;
      t = t / a;
      t = t % 10;
      if (t != nums[i].second) {
        return false;
      }
    }
    return true;
  };
  int ans = -1;
  for (int i = min; i <= max; i++) {
    if (c(i)) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
