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