#include <bits/stdc++.h>
struct Vec {
  double x, y;
};
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T min(T a, T b) {
  if (a < b) return a;
  return b;
}
template <class T>
T max(T a, T b) {
  if (a > b) return a;
  return b;
}
using namespace std;
int main() {
  int N, M, num;
  cin >> N >> M;
  vector<int> cs(N + 1, -1);
  bool bi = false;
  for (int i = (int)(0); i < (int)(M); i++) {
    int c, s;
    cin >> c >> s;
    if ((N != 1 and (c == 1 && s == 0)) || (cs[c] != s && cs[c] != -1)) {
      bi = true;
    }
    cs[c] = s;
  }
  if (bi) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = (int)(1); i < (int)(N + 1); i++) {
    if (cs[i] == -1) continue;
    num += pow(10, N - i) * cs[i];
  }
  cout << num << endl;
  return 0;
}
