#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> rslt;
  vector<int> change_check;
  int n, m;
  cin >> n >> m;
  rslt.assign(n, 0);
  rslt[0] = 1;
  change_check.assign(n, 0);
  int s, c;
  int error = 0;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    if (s == 1 && c == 0) {
      error = 1;
      break;
    }
    if (change_check[s - 1] == 0) {
      rslt[s - 1] = c;
      change_check[s - 1] = 1;
    } else {
      if (rslt[s - 1] == c) continue;
      error = 1;
      break;
    }
  }
  if (error == 1) {
    cout << "-1" << endl;
  } else {
    string s, s_c;
    s = "";
    for (int i = 0; i < n; ++i) {
      s_c = to_string(rslt[i]);
      s = s + s_c;
    }
    cout << s << endl;
  }
}
