#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main(void) {
  int n, m;
  bool invalid = false;
  scanf("%d %d", &n, &m);
  vector<int> v(n, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    scanf("%d %d", &s, &c);
    if ((n != 1 && s == 1 && c == 0) || (v[s - 1] != -1 && v[s - 1] != c)) {
      invalid = true;
      break;
    }
    v[s - 1] = c;
  }
  int ans = 0;
  int digit = 1;
  if (invalid) {
    cout << -1 << endl;
    return 0;
  }
  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;
  }
  cout << ans << endl;
  return 0;
}
