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