#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[5] = {0}, n, m, i, x, y, j;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    if (a[x] == 0) {
      a[x] = y;
    } else {
      a[x] = min(a[x], y);
    }
  }
  for (j = 1; j <= n; j++) {
    if (a[1] == 0) {
      cout << -1;
      break;
    }
    cout << a[j];
  }
  cout << endl;
  return 0;
}
