#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (m == 0) {
    cout << 0;
    return 0;
  }
  int s[m], c[m];
  map<int, int> score;
  int ans = 0;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
    if (s[i] > n && c[i] > 0) {
      cout << -1;
      return 0;
    }
    if (score.count(s[i])) {
      if (score.at(s[i]) != c[i]) {
        cout << -1;
        return 0;
      }
    }
    score[s[i]] = c[i];
  }
  if (n > 1 && score[1] == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < (int)(n); i++) {
    ans = ans * 10 + score[i + 1];
  }
  printf("%d", ans);
  return 0;
}
