#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, 0);
  bool flg = true;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (ans[a - 1] == 0) {
      ans[a - 1] = b;
    } else if (ans[a - 1] != 0 && ans[a - 1] == b) {
      ans[a - 1] = b;
    } else {
      flg = false;
      break;
    }
  }
  if (ans[0] == 0 || flg == false) {
    cout << -1;
  } else {
    for (int i = 0; i < n; i++) {
      cout << ans[i];
    }
  }
  return 0;
}
