#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;
const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  set<P> sp;
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    sp.insert(make_pair(s, c));
  }
  char ans[n];
  for (int i = 0; i < (n); ++i) ans[i] = '0';
  for (P t : sp) {
    if (ans[t.first - 1] != '0') {
      cout << -1 << endl;
      return 0;
    }
    ans[t.first - 1] = t.second + '0';
  }
  if (ans[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (n); ++i) cout << ans[i];
  cout << endl;
  return 0;
}
