#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> str(n, -1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (str[a - 1] > b || str[a - 1] == -1) str[a - 1] = b;
  }
  if (str[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (str[i] == -1) str[i] = 0;
    cout << str[i];
  }
  return 0;
}
