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