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