#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char ans[10];
  int flag = 1;
  for (int i = 0; i < 10; i++) ans[i] = '0';
  for (int i = 1; i <= m; i++) {
    int s;
    int c;
    cin >> s >> c;
    if (ans[s] != '0' && ans[s] != '0' + c) {
      cout << -1 << endl;
      return 0;
    }
    ans[s] = c + '0';
  }
  int pos = 0;
  while (ans[pos] == '0' && pos < 10) {
    pos++;
  }
  int kp = pos;
  int coutflag = 0;
  pos = kp;
  if (pos > 9) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i <= n; i++) {
      cout << ans[pos];
      pos++;
    }
  }
}
