#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF_LL = (long long)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;
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 fish, dog, cat, aaa, aa, abc, ac;
signed main() {
  int N, M;
  cin >> N >> M;
  int s[3] = {-1, -1, -1};
  for (int i = (0); i < (M); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    if (s[a] == -1 || s[a] == b) {
      s[a] = b;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  if (N == 3) {
    if (s[0] == 0) {
      ans = -1;
    } else {
      if (s[0] == -1) s[0] = 1;
      if (s[1] == -1) s[1] = 0;
      if (s[2] == -1) s[2] = 0;
      ans = s[0] * 100 + s[1] * 10 + s[2];
    }
  } else if (N == 2) {
    if (s[0] >= 1) {
      ans = -1;
    } else if (s[1] == 0) {
      ans = -1;
    } else {
      if (s[1] == -1) s[1] = 1;
      if (s[2] == -1) s[2] = 0;
      ans = s[1] * 10 + s[2];
    }
  } else if (N == 1) {
    if (s[0] >= 1 || s[1] >= 1) {
      ans = -1;
    } else {
      if (s[2] == -1) s[2] = 0;
      ans = s[2];
    }
  }
  cout << ans << endl;
}
