#include <bits/stdc++.h>
using namespace std;
namespace Arithmetics {
template <typename T>
T original_pow(T a, T b) {
  T ans = 1;
  for (int i = 0; i < (int)(b); i++) {
    ans *= a;
  }
  return ans;
}
template <typename T>
T gcd(T a, T b) {
  if (a > b) {
    T c = a;
    a = b;
    b = c;
  }
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
template <typename T>
T gcd_of_all(vector<T> v) {
  T temp = v[0];
  for (T elem : v) {
    temp = gcd(temp, elem);
  }
  return temp;
}
template <typename T>
T lcm(T a, T b) {
  T GCD = gcd(a, b);
  return a * b / GCD;
}
template <typename T>
T lcm_of_all(vector<T> v) {
  T temp = v[0];
  for (T elem : v) {
    temp = lcm(temp, elem);
  }
  return temp;
}
}  // namespace Arithmetics
using namespace Arithmetics;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N, -1);
  bool flag = true;
  for (int i = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (vec[s] == -1) {
      if (c == 0) {
        flag = false;
        if (N == 1) {
          flag = true;
          break;
        }
        break;
      }
      vec[s] = c;
    } else {
      if (vec[s] != c) {
        flag = false;
        break;
      }
    }
  }
  int ans = 0;
  if (flag) {
    for (int i = 0; i < N; i++) {
      if (vec[i] == -1) vec[i] = 0;
    }
    vec[0] == 0 ? vec[0] = 1 : 1;
    for (int i = 0; N - i > 0; i++) {
      ans += vec[i] * pow(10, N - 1 - i);
    }
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
