#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0;
  int keta = 0;
  cin >> keta;
  int kazu = 0;
  cin >> kazu;
  vector<int> data(keta);
  vector<int> shitei(keta);
  for (int i = 0; i < kazu; i++) {
    cin >> shitei[i];
    cin >> data[i];
  }
  for (int i = 0; i < kazu; i++) {
    for (int j = i; j < kazu; j++) {
      if ((data[i] != data[j] && shitei[i] == shitei[j]) ||
          shitei[i] == 1 && data[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < kazu; i++) {
    int zyou = 1;
    for (int j = 0; j < keta - shitei[i]; j++) {
      zyou *= 10;
    }
    if ((ans / zyou) % 10 == 0) ans += data[i] * zyou;
  }
  cout << ans << endl;
  return 0;
}
