#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, i;
  cin >> N >> M;
  int s[M], c[M];
  for (i = 0; i < M; i++) cin >> s[i] >> c[i];
  int dig[N + 1];
  for (i = 1; i < N + 1; i++) {
    dig[i] = 100;
  }
  for (i = 0; i < M; i++) {
    if (dig[s[i]] < 10 && c[i] != dig[s[i]] || s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    dig[s[i]] = c[i];
  }
  for (i = 1; i < N + 1; i++) {
    if (dig[i] > 9) dig[i] = 0;
    cout << dig[i];
  }
  cout << endl;
  return 0;
}
