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