#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> dig(n + 1, -1);
  bool can = true;
  for (size_t i = 0; i < m; i++) {
    int si, ci;
    cin >> si >> ci;
    if (dig[si] != -1 && dig[si] != ci) {
      can = false;
      break;
    }
    if (si == 1 && ci == 0) {
      can = false;
      break;
    }
    if (si > n) {
      can = false;
      break;
    }
    dig[si] = ci;
  }
  if (can == false) {
    cout << -1 << endl;
  } else {
    int res = 0;
    for (size_t i = 1; i <= n; i++) {
      if (dig[i] >= 0) {
        res += pow(10, (n - i)) * dig[i];
      }
    }
    cout << res << endl;
  }
}
