#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  long long N, M, ans[10];
  cin >> N >> M;
  for (long long i = 0; i < M; i++) {
    long long s, c;
    cin >> s >> c;
    if (s == 1 && c == 0 && N > 1) {
      cout << -1 << endl;
      return 0;
    } else if (ans[s - 1] == 0 || ans[s - 1] == c)
      ans[s - 1] = c;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N == 1)
    cout << ans[0];
  else {
    if (ans[0])
      cout << ans[0];
    else
      cout << 1;
    for (long long i = 1; i < N; i++) cout << ans[i];
  }
  return 0;
}
