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