#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M);
  vector<int> C(M);
  for (int i = 0; i < (M); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    S[i] = s;
    C[i] = c;
  }
  vector<vector<int>> target(N);
  int ans = -1;
  for (int i = 0; i < (M); i++) {
    target[S[i]].push_back(C[i]);
  }
  bool end = false;
  for (int i = 0; i < (N); i++) {
    if (end) break;
    int minv = 10;
    for (auto t : target[i]) {
      if (t < minv) minv = t;
    }
    if (minv == 10) minv = 0;
    if (i == 0 && minv == 0) {
      cout << -1;
      end = true;
      break;
    }
    cout << minv;
  }
  cout << endl;
  return 0;
}
