#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, m;
  cin >> n >> m;
  long long check[n];
  for (long long i = 0; i < n; i++) check[i] = 10;
  for (long long i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    if (n == 1)
      check[s - 1] = min(check[s - 1], c);
    else if (n > 1 && s == 1 && c != 0)
      check[s - 1] = min(check[s - 1], c);
    else if (n > 1 && s != 1)
      check[s - 1] = min(check[s - 1], c);
  }
  for (long long i = 0; i < n; i++) {
    if (check[i] == 10) check[i] = 0;
  }
  bool c = true;
  if (check[0] == 0 && n != 1) c = false;
  if (c == true) {
    for (long long i = 0; i < n; i++) cout << check[i];
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
