#include <bits/stdc++.h>
using namespace std;
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;
}
const long long INF = 1LL << 60;
int main() {
  int N, M;
  cin >> N >> M;
  bool flag = true;
  vector<int> sc(3, -1);
  for (int i = (0); i < (M); i++) {
    int s, c;
    cin >> s >> c;
    if (sc[s - 1] == -1 || sc[s - 1] == c) {
      sc[s - 1] = c;
    } else {
      flag = false;
    }
  }
  if (sc[0] == 0 && N >= 2) {
    flag = false;
  }
  if (flag) {
    if ((sc[0] == 0 || sc[0] == -1) && N == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << (sc[0] == -1 ? 1 : sc[0]);
      cout << (sc[1] == -1 ? 0 : sc[1]);
      cout << (sc[2] == -1 ? 0 : sc[2]);
      cout << endl;
      return 0;
    }
  } else {
    cout << -1 << endl;
  }
  return 0;
}
