#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* first) -> decltype(cerr << *first, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() { cerr << '\n'; }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug& operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug& operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
};
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, q, first, second;
  cin >> n >> q;
  long long a[n];
  memset(a, -1, sizeof(a));
  for (long long i = 0; i < q; i++) {
    cin >> first >> second;
    --first;
    if (a[first] == -1) {
      a[first] = second;
    } else {
      if (a[first] != second) {
        cout << -1;
        return 0;
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    if (i == 0) {
      if (a[i] == -1)
        cout << 1;
      else {
        if (a[i] == 0) {
          cout << -1;
          return 0;
        } else
          cout << a[i];
      }
    } else {
      if (a[i] == -1)
        cout << 0;
      else
        cout << a[i];
    }
  }
  return 0;
}
