#include <bits/stdc++.h>
using namespace std;
int main(void) {
  unsigned long int s[5], c[5], N = 0, M = 0, count = 0;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  unsigned long int out[N];
  for (int i = 0; i < N; i++) {
    out[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    if ((out[s[i]] == 0 || out[s[i]] == c[i]) && (s[i] != 0 || c[i] != 0)) {
      out[s[i]] = c[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (out[0] == 0) {
    out[0] = 1;
  }
  for (int i = 0; i < N; i++) {
    cout << out[i];
  }
  cout << endl;
  return 0;
}
