#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* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const int MOD = 1000000007;
const long long INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> v(100);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    if (v[x - 1] == 0 || v[x - 1] == y)
      v[x - 1] = y;
    else {
      cout << -1;
      return 0;
    }
  }
  string res = "";
  bool first = true;
  for (int i = n - 1; i >= 0; i--) {
    if (v[i] == 0 && first) {
      cout << -1;
      return 0;
    } else if (v[i] && first) {
      res += to_string(v[i]);
      first = false;
    } else {
      res += to_string(v[i]);
    }
  }
  reverse(res.begin(), res.end());
  cout << res;
  return 0;
}
