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