#include <bits/stdc++.h>
using ll = long long int;
using ul = unsigned long long int;
namespace lamlib {
template <class T>
inline T abs(const T &a) {
  return (a > 0) ? a : -a;
}
ul gcd(ul a, ul b) { return (!b) ? a : gcd(b, a % b); }
}  // namespace lamlib
int main(int argc, char *argv[]) {
  ll n, m;
  std::cin >> n >> m;
  bool out = false;
  std::vector<ll> arr(n, 10);
  for (ll i = 0; i < m; ++i) {
    ll s, c;
    std::cin >> s >> c;
    if (arr[s - 1] == 10)
      arr[s - 1] = c;
    else if (arr[s - 1] != c)
      out = true;
  }
  if (out)
    std::cout << -1 << std::endl;
  else {
    if (n == 1) {
      if (m == 0)
        std::cout << -1 << std::endl;
      else
        std::cout << arr[0] << std::endl;
    } else {
      if (arr[0] == 0)
        std::cout << -1;
      else
        for (ll i = 0; i < n; ++i) {
          if (arr[i] != 10)
            std::cout << arr[i];
          else if (i == 0)
            std::cout << 1;
          else
            std::cout << 0;
        }
      std::cout << std::endl;
    }
  }
  return 0;
}
