#include <bits/stdc++.h>
using namespace std;
using s32 = int32_t;
using u32 = uint32_t;
using u64 = uint64_t;
int main() {
  u32 N, M;
  cin >> N >> M;
  vector<u32> ans(N);
  vector<bool> dcd(N);
  for (u32 k = 0; k < M; k++) {
    u32 s;
    u32 c;
    cin >> s >> c;
    if (dcd[s - 1] && ans[s - 1] != c) {
      cout << -1;
      return 0;
    }
    dcd[s - 1] = true;
    ans[s - 1] = c;
  }
  if (ans[0] == 0) {
    cout << -1;
    return 0;
  }
  for (u32 k = 0; k < M; k++) {
    cout << ans[k];
  }
  return 0;
}
