#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  vector<int> v;
  bool invalid = false;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    v.push_back(-1);
  }
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (v[s] != -1 && v[s] != c) {
      invalid = true;
      break;
    }
    v[s] = c;
  }
  int ans = 0;
  int digit = 1;
  if (!invalid) {
    for (int i = n - 1; i > 0; i++) {
      int num = v[i];
      if (num != -1) {
        ans += num * digit;
      }
      digit *= 10;
    }
    if (v[0] == -1) {
      ans += v[0] * digit;
    } else {
      ans += digit;
    }
  } else {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
