#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class T>
using V = vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int ddx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
int ddy[8] = {0, -1, 0, 1, 1, -1, 1, -1};
char dir[4] = {'u', 'l', 'd', 'r'};
long long int cmp(pair<long long int, long long int> a,
                  pair<long long int, long long int> b) {
  if (a.first != b.first)
    return a.first < b.first;
  else
    return a.second < b.second;
}
struct mint {
  using ull = unsigned long long int;
  ull v;
  mint(long long int vv = 0) { s(vv % 1000000007 + 1000000007); }
  mint& s(ull vv) {
    v = vv < 1000000007 ? vv : vv - 1000000007;
    return *this;
  }
  mint operator-() const { return mint() - *this; }
  mint& operator+=(const mint& val) { return s(v + val.v); }
  mint& operator-=(const mint& val) { return s(v + 1000000007 - val.v); }
  mint& operator*=(const mint& val) {
    v = ull(v) * val.v % 1000000007;
    return *this;
  }
  mint& operator/=(const mint& val) { return *this *= val.inv(); }
  mint operator+(const mint& val) { return mint(*this) += val; }
  mint operator-(const mint& val) { return mint(*this) -= val; }
  mint operator*(const mint& val) { return mint(*this) *= val; }
  mint operator/(const mint& val) { return mint(*this) /= val; }
  mint pow(int n) const {
    mint res(1), x(*this);
    while (n) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  mint inv() const { return pow(1000000007 - 2); }
  friend ostream& operator<<(ostream& os, const mint& val) {
    return os << val.v;
  }
  bool operator<(const mint& val) const { return v < val.v; }
  bool operator==(const mint& val) const { return v == val.v; }
  bool operator>(const mint& val) const { return v > val.v; }
};
const long long int MAX = 2000010;
mint fac[MAX], finv[MAX], inv[MAX];
void init() {
  fac[0] = fac[1] = 1;
  for (int i = 1; i < MAX; i++) fac[i] = fac[i - 1] * i;
  finv[MAX - 1] = fac[MAX - 1].inv();
  for (int i = MAX - 2; i >= 0; i--) finv[i] = finv[i + 1] * (i + 1);
  for (int i = MAX - 2; i >= 1; i--) inv[i] = finv[i] + fac[i - 1];
}
mint factor(long long int n, long long int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * finv[k];
}
mint COM(long long int n, long long int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * finv[k] * finv[n - k];
}
long long int modpow(long long int a, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    n >>= 1;
  }
  return res;
}
long long int waru(long long int a, long long int b) {
  return a * modpow(b, 1000000007 - 2) % 1000000007;
}
long long int permutation(long long int n, long long int r) {
  long long int a = 1;
  for (long long int i = n - r + 1; i <= n; i++) a *= i;
  return a;
}
bool color[3][3];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int ans[3];
  for (int i = 0; i < 3; i++) ans[i] = -1;
  for (int i = 0; i < m; i++) {
    if (ans[s[i]] == -1) {
      ans[s[i]] = c[i];
      if (c[i] == 0 && n == 2 && s[i] == 1) {
        cout << -1 << endl;
        return 0;
      } else if (c[i] == 0 && n == 3 && s[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      if (c[i] != ans[s[i]]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (n == 1) {
    if (ans[2] == -1) ans[2] = 1;
    cout << ans[2] << endl;
  } else if (n == 2) {
    if (ans[2] == -1) ans[2] = 1;
    if (ans[1] == -1) ans[1] = 1;
    cout << ans[1] << ans[2] << endl;
  } else {
    if (ans[2] == -1) ans[2] = 1;
    if (ans[1] == -1) ans[1] = 1;
    if (ans[0] == -1) ans[0] = 1;
    cout << ans[0] << ans[1] << ans[2] << endl;
  }
  return 0;
}
