#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
int main() {
  long n, m;
  cin >> n >> m;
  map<long, long> l;
  bool z = true;
  for (int i = 0; i < m; i++) {
    long a, b;
    cin >> a >> b;
    if (l.count(a) && l[a] != b) {
      z = false;
      break;
    }
    l[a] = b;
    if (n != 1 && a == 1 && b == 0) {
      z = false;
      break;
    }
    if (a > n) {
      z = false;
      break;
    }
  }
  long ans = 0;
  long n3[] = {100, 10, 1}, n2[] = {10, 1};
  if (z) {
    for (auto i : l) {
      ans += i.second * n3[i.first - 1];
    }
    cout << ans << endl;
  } else
    cout << "-1" << endl;
  return 0;
}
