#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1e16;
const long double EPS = 1e-10;
const long double PI = 3.141592653589793;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const pair<long long, long long> fd[] = {make_pair(1, 0), make_pair(-1, 0),
                                         make_pair(0, 1), make_pair(0, -1)};
long long n, m, ans[3];
signed main() {
  cin >> n >> m;
  for (long long i = (0); i < (n); i++) ans[i] = -1;
  for (long long i = (0); i < (m); i++) {
    long long s, c;
    cin >> s >> c;
    if (ans[s - 1] == -1 || ans[s - 1] == c) {
      ans[s - 1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long i = (0); i < (n); i++)
    if (ans[i] == -1) ans[i] = 0;
  long long ret = 0;
  if (n == 1) ret = ans[0];
  if (n == 2) {
    if (ans[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    ret = ans[0] * 10 + ans[1];
  }
  if (n == 3) {
    if (ans[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    ret = ans[0] * 100 + ans[1] * 10 + ans[2];
  }
  cout << ret << endl;
}
