#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> numbers;
  for (int i = (0); i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    if (!numbers.count(s - 1))
      numbers[s - 1] = c;
    else if (numbers.at(s - 1) > c)
      numbers[s - 1] = c;
  }
  bool flag = false;
  for (int i = (0); i < (N); ++i) {
    if (!flag && (!numbers.count(i) || numbers.at(i) == 0)) break;
    if (!numbers.count(i)) numbers[i] = 0;
    flag = true;
  }
  if (flag) {
    for (int i = (0); i < (N); ++i) cout << numbers.at(i);
    cout << endl;
  } else
    cout << -1 << endl;
}
