#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 1001001001;
template <class Type>
Type mod_pow(Type a, Type n, Type mod) {
  Type res = 1;
  while (0 < n) {
    if (n & 1) {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
template <class Type>
Type gcd(Type x, Type y) {
  Type r;
  if (x < y) swap(x, y);
  while (0 < y) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}
template <class Type>
Type lcm(Type x, Type y) {
  return x * y / gcd(x, y);
}
template <class Type>
bool is_prime(Type x) {
  if (x == 2) return true;
  if (x < 2 || x % 2 == 0) return false;
  for (Type i = 3; i <= sqrt(x); i += 2) {
    if (x % i == 0) return false;
  }
  return true;
}
template <class Type>
vector<bool> eratos(Type n) {
  vector<bool> isPrime(n + 1, true);
  isPrime[0] = isPrime[1] = false;
  for (Type i = 2; i <= n; i++) {
    if (isPrime[i]) {
      Type j = i + i;
      while (j <= n) {
        isPrime[j] = false;
        j = j + i;
      }
    }
  }
  return isPrime;
}
bool binary_search_judge(vector<int> a, int index, int key) {
  if (key <= a[index])
    return true;
  else
    return false;
}
int binary_search(vector<int> a, int key) {
  int ng = -1;
  int ok = a.size();
  while (1 < abs(ng - ok)) {
    int mid = (ng + ok) / 2;
    if (binary_search_judge(a, mid, key))
      ok = mid;
    else
      ng = mid;
  }
  return a[ok] == key;
}
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
template <class Type>
mint inv_nCk(Type n, Type k) {
  mint x = 1, y = 1;
  for (Type i = 0; i < k; i++) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};
template <class Type>
Type pascal_nCk(Type n, Type k, Type mod) {
  vector<vector<Type>> dp(n + 1, vector<Type>(n + 1, 0));
  for (int i = 0; i <= n; i++) {
    dp[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod;
    }
  }
  return dp[n][k];
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s < n && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (num[s - 1] == -1 || num[s - 1] == c) {
      num[s - 1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[0] == -1) num[0] = 1;
  for (int i = 1; i < n; i++) {
    if (num[i] == -1) num[i] = 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += num[i] * pow(10, n - i - 1);
  }
  cout << ans << endl;
}
