#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  int ans = 1000000007;
  int ansf = 0;
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    bool flag = true;
    string str = to_string(i);
    for (int j = 0; j < (m); ++j) {
      string strc = to_string(c[j]);
      if (str.substr(s[j] - 1, 1) != strc) flag = false;
    }
    if (flag) {
      ans = min(ans, i);
      ansf++;
    }
  }
  if (m == 0 && n == 1) {
    ansf++;
    ans = 0;
  } else if (m == 0 && n != 1) {
    ansf++;
    ans = pow(10, n - 1);
  }
  if (ansf) {
    cout << ans;
  } else {
    cout << "-1";
  }
}
