#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using IP = pair<int, P>;
using LLP = pair<ll, LP>;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
static int popcount(int x) {
  return __builtin_popcount(static_cast<unsigned int>(x));
}
static int popcount(unsigned int x) { return __builtin_popcount(x); }
static int popcount(long x) {
  return __builtin_popcountl(static_cast<unsigned long>(x));
}
static int popcount(unsigned long x) { return __builtin_popcountl(x); }
static int popcount(long long x) {
  return __builtin_popcountll(static_cast<unsigned long long>(x));
}
static int popcount(unsigned long long x) { return __builtin_popcountll(x); }
namespace std {
template <typename T, typename U>
struct hash<pair<T, U> > {
  size_t operator()(const pair<T, U> &key) const noexcept {
    size_t h1 = hash<T>()(key.first);
    size_t h2 = hash<U>()(key.second);
    return h1 ^ (h2 << 1);
  }
};
}  // namespace std
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  size_t sz = v.size();
  os << "[";
  for (size_t i = 0; i < sz - 1; i++) {
    os << v[i] << ", ";
  }
  os << v[sz - 1] << "]";
  return os;
}
template <typename T, int N,
          typename std::enable_if<!std::is_same<T, char>::value,
                                  std::nullptr_t>::type = nullptr>
ostream &operator<<(ostream &os, const T (&v)[N]) {
  os << "[";
  for (size_t i = 0; i < N - 1; i++) {
    os << v[i] << ", ";
  }
  os << v[N - 1] << "]";
  return os;
}
template <typename T>
void printArray(T *arr, size_t sz) {
  cerr << "[";
  for (size_t i = 0; i < sz - 1; i++) {
    cerr << arr[i] << ",";
  }
  cerr << arr[sz - 1] << "]" << endl;
}
static inline ll mod(ll x, ll m) {
  ll y = x % m;
  return (y >= 0 ? y : y + m);
}
struct Compare {
  bool operator()(const int x, const int y) { return x < y; }
};
int N, M;
map<int, int> m;
void solve() {
  int ans = 0;
  for (auto x : m) {
    int b = 1;
    for (ll i = static_cast<ll>(0); i < static_cast<ll>(N - x.first); ++i)
      b *= 10;
    ans += x.second * b;
  }
  int b = 1;
  for (ll i = static_cast<ll>(0); i < static_cast<ll>(N - 1); ++i) b *= 10;
  if (ans < b) ans += b;
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (ll i = static_cast<ll>(0); i < static_cast<ll>(M); ++i) {
    int s, c;
    cin >> s >> c;
    if (N > 1 && s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (m.find(s) != m.end()) {
      if (m[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      m[s] = c;
    }
  }
  solve();
  return 0;
}
