#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, pos, val;
  int ans = 0;
  cin >> N >> M;
  vector<int> v(N + 1, 10);
  while (M--) {
    cin >> pos >> val;
    if (v[pos] > val && val != 0) {
      v[pos] = val;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (v[i] == 10) {
      v[i] = 0;
    }
  }
  if (v[1] == 0) {
    cout << -1;
  } else {
    for (int i = 1; i <= N; i++) {
      ans = ans * 10 + v[i];
    }
  }
  cout << ans;
}
