#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> ans(n, -1);
  bool flag = true;
  for (int64_t i = 0, __i_length = (m); i < __i_length; i++) {
    int64_t s, c;
    cin >> s >> c;
    if (ans[s - 1] < 0) {
      ans[s - 1] = c;
    } else {
      flag = (ans[s - 1] == c);
    }
  }
  if (flag && ans[0] != 0) {
    if (ans[0] == -1) ans[0] = 1;
    for (int64_t i = 0, __i_length = (n); i < __i_length; i++)
      cout << ((ans[i] == -1) ? 0 : ans[i]);
    puts("");
  } else {
    cout << -1 << endl;
  }
}
