#include <bits/stdc++.h>
using namespace std;
int solver() {
  int n, m;
  cin >> n >> m;
  int num[n];
  for (int i = 0; i < n; i++) {
    num[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (num[s - 1] != c and num[s - 1] != -1) {
      return -1;
    }
    num[s - 1] = c;
  }
  int ans = 0;
  bool prev_is_zero = false;
  for (int i = 0; i < n; i++) {
    if (num[n - 1 - i] == -1)
      continue;
    else if (num[n - 1 - i] == 0) {
      prev_is_zero = true;
    } else if (num[n - 1 - i] > 0) {
      ans += num[n - 1 - i] * pow(10, i);
      prev_is_zero = false;
    }
  }
  if (prev_is_zero) ans = -1;
  if (prev_is_zero and n == 1) ans = 0;
  return ans;
}
int main() {
  int ans = solver();
  cout << ans << "\n";
  return 0;
}
