#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (long long)1000000007 * 1000000007;
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;
}
int main() {
  long long N, M;
  cin >> N >> M;
  int p[3];
  for (int i = 0; i < (int)(N); i++) {
    p[i] = -1;
  }
  int res = 0;
  for (int i = 0; i < (int)(M); i++) {
    int n, m;
    cin >> n >> m;
    if (p[n - 1] == -1 || p[n - 1] == m) {
      p[n - 1] = m;
    } else {
      res = -1;
    }
  }
  if (p[0] == 0) {
    if (N == 1) {
      cout << 0 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  if (p[0] == 0) {
    res = -1;
    cout << res << endl;
    return 0;
  }
  for (int i = 0; i < (int)(N); i++) {
    if (p[i] == -1) {
      p[i] = 0;
    }
  }
  if (res != -1) {
    for (int i = 0; i < (int)(N); i++) {
      res *= 10;
      res += p[i];
    }
  }
  if (res < pow(10, N - 1)) {
    res += pow(10, N - 1);
  }
  cout << res << endl;
  return 0;
}
