#include <bits/stdc++.h>
using namespace std;
const vector<long long> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<long long> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const long long MOD = (1000000007);
const long long INF = (1LL << 60);
const double EPS = (1 >> 30);
template <class tuple<long long, long long, long long> >
inline bool chmin(tuple<long long, long long, long long>& a,
                  tuple<long long, long long, long long> b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
} template <class tuple<long long, long long, long long> >
inline bool chmax(tuple<long long, long long, long long>& a,
                  tuple<long long, long long, long long> b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
} signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m);
  vector<long long> c(m);
  for (long long i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<long long> a(10, -1);
  long long ng = 0;
  for (long long i = 0; i < m; ++i) {
    if (a[s[i]] == -1 || a[s[i]] == c[i]) {
      a[s[i]] = c[i];
    } else {
      ng++;
    }
  }
  if (n == 2) {
    if (a[0] == 0) ng++;
  } else if (n == 3) {
    if (a[0] == 0) ng++;
  }
  long long sum = 0;
  for (long long i = 0; i < n; ++i) {
    if (a[i] == -1) a[i] = 0;
    sum += a[i];
  }
  if (sum == 0 && n > 1) a[0] = 1;
  if (ng != 0)
    cout << -1 << endl;
  else {
    for (long long i = 0; i < n; ++i) {
      cout << a[i];
    }
    cout << endl;
  }
}
