#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
signed main() {
  int n, m;
  cin >> n >> m;
  int ans[n];
  for (int i = 0; i < (n); i++) ans[i] = -1;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    s--;
    if (ans[s] == c || ans[s] == -1) {
      ans[s] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < (n); i++) {
    if (i == 0) {
      if (ans[i] == 0 || ans[i] == -1)
        cout << 1;
      else
        cout << ans[i];
    } else {
      if (ans[i] == -1)
        cout << 0;
      else
        cout << ans[i];
    }
  }
}
