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