#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  bool judge1 = 0, judge2 = 0;
  vector<int> s(N);
  for (int i = 0; i < (int)(M); i++) {
    int a, b;
    cin >> a >> b;
    s[a - 1] = b;
    if (s[a - 1] != 0) s[a - 1] = min(b, s[a - 1]);
  }
  if (s[0] != 0) {
    for (int i = 0; i < (int)(N); i++) {
      cout << s[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
