#include <bits/stdc++.h>
using namespace std;
using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using pss = pair<string, string>;
template <typename _KTy, typename _Ty>
ostream& operator<<(ostream& o, const pair<_KTy, _Ty>& m) {
  o << "{" << m.first << ", " << m.second << "}";
  return o;
}
template <typename _KTy, typename _Ty>
ostream& operator<<(ostream& o, const map<_KTy, _Ty>& m) {
  if (m.empty()) {
    o << "{ }";
    return o;
  }
  o << "{" << *m.begin();
  for (auto itr = ++m.begin(); itr != m.end(); itr++) {
    o << ", " << *itr;
  }
  o << "}";
  return o;
}
template <typename _KTy, typename _Ty>
ostream& operator<<(ostream& o, const unordered_map<_KTy, _Ty>& m) {
  if (m.empty()) {
    o << "{ }";
    return o;
  }
  o << "{" << *m.begin();
  for (auto itr = ++m.begin(); itr != m.end(); itr++) {
    o << ", " << *itr;
  }
  o << "}";
  return o;
}
template <typename _Ty>
ostream& operator<<(ostream& o, const vector<_Ty>& v) {
  if (v.empty()) {
    o << "{ }";
    return o;
  }
  o << "{" << v.front();
  for (auto itr = ++v.begin(); itr != v.end(); itr++) {
    o << ", " << *itr;
  }
  o << "}";
  return o;
}
template <typename _Ty>
ostream& operator<<(ostream& o, const set<_Ty>& s) {
  if (s.empty()) {
    o << "{ }";
    return o;
  }
  o << "{" << *(s.begin());
  for (auto itr = ++s.begin(); itr != s.end(); itr++) {
    o << ", " << *itr;
  }
  o << "}";
  return o;
}
template <typename _Ty>
ostream& operator<<(ostream& o, const unordered_set<_Ty>& s) {
  if (s.empty()) {
    o << "{ }";
    return o;
  }
  o << "{" << *(s.begin());
  for (auto itr = ++s.begin(); itr != s.end(); itr++) {
    o << ", " << *itr;
  }
  o << "}";
  return o;
}
template <typename _Ty>
ostream& operator<<(ostream& o, const stack<_Ty>& s) {
  if (s.empty()) {
    o << "{ }";
    return o;
  }
  stack<_Ty> t(s);
  o << "{" << t.top();
  t.pop();
  while (!t.empty()) {
    o << ", " << t.top();
    t.pop();
  }
  o << "}";
  return o;
}
template <typename _Ty>
ostream& operator<<(ostream& o, const list<_Ty>& l) {
  if (l.empty()) {
    o << "{ }";
    return o;
  }
  o << "{" << l.front();
  for (auto itr = ++l.begin(); itr != l.end(); ++itr) {
    o << ", " << *itr;
  }
  o << "}";
  return o;
}
template <typename _KTy, typename _Ty>
istream& operator>>(istream& is, pair<_KTy, _Ty>& m) {
  is >> m.first >> m.second;
  return is;
}
template <typename _Ty>
istream& operator>>(istream& is, vector<_Ty>& v) {
  for (size_t t = 0; t < v.size(); t++) is >> v[t];
  return is;
}
namespace aux {
template <typename Ty, unsigned N, unsigned L>
struct tp {
  static void print(ostream& os, const Ty& v) {
    os << get<N>(v) << ", ";
    tp<Ty, N + 1, L>::print(os, v);
  }
};
template <typename Ty, unsigned N>
struct tp<Ty, N, N> {
  static void print(ostream& os, const Ty& v) { os << get<N>(v); }
};
}  // namespace aux
template <typename... Tys>
ostream& operator<<(ostream& os, const tuple<Tys...>& t) {
  os << "{";
  aux::tp<tuple<Tys...>, 0, sizeof...(Tys) - 1>::print(os, t);
  os << "}";
  return os;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T& val) {
  fill((T*)array, (T*)(array + N), val);
}
void dump_func() { cerr << endl; }
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
  cerr << head;
  if (sizeof...(Tail) == 0) {
    cerr << " ";
  } else {
    cerr << ", ";
  }
  dump_func(move(tail)...);
}
class Timer {
 public:
  double t = 0;
  Timer() {}
  static double time() {
    unsigned long long a, d;
    __asm__ volatile("rdtsc" : "=a"(a), "=d"(d));
    return (d << 32 | a) / 2.8e9;
  }
  void measure() { t = time() - t; }
  double elapsedMs() { return (time() - t) * 1000.0; }
} timer;
struct Xorshift {
  uint64_t x = 88172645463325252LL;
  unsigned next_int() {
    x = x ^ (x << 7);
    return x = x ^ (x >> 9);
  }
  unsigned next_int(unsigned mod) {
    x = x ^ (x << 7);
    x = x ^ (x >> 9);
    return x % mod;
  }
  unsigned next_int(unsigned l, unsigned r) {
    x = x ^ (x << 7);
    x = x ^ (x >> 9);
    return x % (r - l + 1) + l;
  }
  double next_double() { return double(next_int()) / UINT_MAX; }
} rnd;
template <typename T>
void shuffle_vector(vector<T>& v, Xorshift& rnd) {
  int n = v.size();
  for (int i = n - 1; i >= 1; i--) {
    int r = rnd.next_int(i);
    swap(v[i], v[r]);
  }
}
void assign_block(vector<vector<int>>& blocks, const vector<int>& perm,
                  const vector<int>& a) {
  for (int i = 0; i < a[0]; i++) {
    blocks[0][i] = perm[i];
  }
  for (int i = a[0]; i < a[0] + a[1]; i++) {
    blocks[1][i - a[0]] = perm[i];
  }
  for (int i = a[0] + a[1]; i < a[0] + a[1] + a[2]; i++) {
    blocks[2][i - a[0] - a[1]] = perm[i];
  }
}
bool is_valid(const vector<vector<int>>& blocks, const vector<int>& a) {
  for (int i = 0; i < 3; i++) {
    for (int j = 1; j < a[i]; j++) {
      if (blocks[i][j] < blocks[i][j - 1]) return false;
    }
    if (i > 0) {
      for (int j = 0; j < a[i]; j++) {
        if (blocks[i][j] < blocks[i - 1][j]) return false;
      }
    }
  }
  return true;
}
int digitsum(int x) {
  int ret = 0;
  while (x) {
    ret += x % 10;
    x /= 10;
  }
  return ret;
}
int main(int argc, char** argv) {
  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];
  vector<set<int>> digits(N + 1);
  for (int i = 0; i < M; i++) {
    int d = s[i];
    digits[d].insert(c[i]);
  }
  for (int i = 1; i <= N; i++)
    if (digits[i].size() >= 2) {
      cout << -1 << endl;
      return 0;
    }
  if (N > 1 && digits[1].size() == 1 && (*digits[1].begin()) == 0) {
    cout << -1 << endl;
    return 0;
  }
  string sans(N, '9');
  for (int i = 1; i <= N; i++) {
    if (digits[i].size()) {
      sans[i - 1] = (*digits[i].begin()) + '0';
    } else {
      sans[i - 1] = '0';
    }
  }
  cout << sans << endl;
  return 0;
}
