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