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