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