#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int *ans;
  ans = new int[N];
  for (int i = 0; i < (int)(N); i++) {
    ans[i] = 0;
  }
  int ret = 0;
  for (int i = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    if (ans[s - 1] != 0 && ans[s - 1] != c || s == 1 && c == 0) {
      ret = -1;
      break;
    } else {
      ans[s - 1] = c;
    }
  }
  if (ret == -1) {
    cout << ret << endl;
  } else {
    for (int i = 0; i < (int)(N); i++) {
      ret = ret * 10 + ans[i];
    }
    cout << ret << endl;
  }
}
