#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  for (int i = 0; i < M; i++) {
    cin >> a[i];
    cin >> b[i];
  }
  vector<int> c(N, 0);
  vector<int> d(N, 0);
  bool can = true;
  for (int i = 0; i < M; i++) {
    if (d[a[i] - 1] == 0 || c[a[i] - 1] == b[i]) {
      c[a[i] - 1] = b[i];
      d[a[i] - 1]++;
    } else {
      can = false;
      break;
    }
  }
  if (N > 1 && c[0] == 0) {
    can = false;
  }
  int ans = 0;
  if (can) {
    for (int i = 0; i < N; i++) {
      ans += c[i] * pow(10, 2 - i);
    }
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
