#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> cs(N + 1, 10);
  int s, c;
  for (int i = 0; i < (int)(M); i++) {
    cin >> s >> c;
    cs[s] = min(cs[s], c);
  }
  for (int i = 0; i <= N; i++) {
    if (cs[i] == 10) {
      cs[i] = 0;
    }
  }
  if (cs[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll sum = cs[1];
  for (int i = 2; i <= N; i++) {
    sum = sum * 10 + cs[i];
  }
  cout << sum << endl;
  return 0;
}
