#include <bits/stdc++.h>
using namespace std;
struct data {
  int s;
  int c;
};
int main() {
  int n, m;
  cin >> n >> m;
  struct data d[6];
  for (int i = 0; i < m; i++) {
    cin >> d[i].s >> d[i].c;
  }
  int flag = 0;
  for (int i = 0; i < m; i++) {
    if (d[i].s == n) {
      flag = 1;
    }
  }
  if (flag == 0) {
    cout << -1 << endl;
  } else {
    int min[3];
    for (int i = 1; i <= n; i++) {
      min[i] = 10;
    }
    for (int i = 1; i <= n; i++) {
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < m; j++) {
        if (d[j].s == i) {
          if (min[i] > d[j].c) {
            min[i] = d[j].c;
          }
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (min[i] == 10) {
        min[i] = 0;
      }
    }
    for (int i = 1; i <= n; i++) {
      cout << min[i];
    }
    cout << endl;
  }
  return 0;
}
