#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using pii = pair<int64_t, int64_t>;
constexpr int64_t INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int64_t mod1 = 1e9 + 7;
constexpr int64_t mod2 = 998244353;
template <class A, class B>
inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B>
inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T> >;
template <class T>
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
inline int64_t square(int64_t a) { return a * a; }
inline int64_t updiv(int64_t a, int64_t b) { return (a + b - 1) / b; }
constexpr int64_t dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int64_t dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> num(n + 1, -1);
  for (int64_t i = 0; i < (m); ++i) {
    int64_t s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      return cout << "-1\n", 0;
    } else if (num[s] == -1) {
      num[s] = c;
    } else if (num[s] != c) {
      return cout << "-1\n", 0;
    }
  }
  string res;
  for (int64_t i = 1; i <= (n); ++i) {
    if (i == 1) {
      if (num[i] == -1) {
        cout << 1;
      } else {
        cout << num[i];
      }
    } else {
      if (num[i] == -1) {
        cout << 0;
      } else {
        cout << num[i];
      }
    }
  }
  cout << '\n';
  return 0;
}
