#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n = 0, m = -1;
  cin >> n >> m;
  assert(n >= 1 && n <= 3);
  assert(m >= 0 && m <= 5);
  int ret_ary[3] = {0, 0, 0};
  for (int i = 0, i_len = (m); i < i_len; ++i) {
    int s = 0, c = -1;
    cin >> s >> c;
    assert(s >= 1 && s <= n);
    assert(c >= 0 && c <= 9);
    if (ret_ary[s - 1] == 0 || ret_ary[s - 1] > c) {
      ret_ary[s - 1] = c;
    }
  }
  int answer = -1;
  if (ret_ary[3 - n] != 0) {
    answer = 0;
    for (int i = 0, i_len = (n); i < i_len; ++i) {
      answer += pow(10, i) * ret_ary[3 - 1 - i];
    }
  }
  cout << answer << endl;
  return 0;
}
