#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, s, c, flag = 0, ans = 0;
  cin >> n >> m;
  vector<int> set(m, -1);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    if (set.at(s - 1) == -1) {
      set.at(s - 1) = c;
    } else {
      if (set.at(s - 1) != c) {
        flag = 1;
        break;
      }
    }
  }
  if (set.at(0) == -1 || set.at(0) == 0) flag = 1;
  if (flag) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < (int)(m); i++) {
      if (set.at(i) == -1) {
        ans *= 10;
      } else {
        ans = ans * 10 + set.at(i);
      }
    }
    cout << ans << endl;
  }
}
