#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 7;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
string s;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> ans(n, -1);
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    --x;
    if (ans[x] == -1) {
      ans[x] = y;
    } else if (ans[x] != -1) {
      if (ans[x] == y) {
      } else {
        cout << -1 << '\n';
        return;
      }
    }
  }
  if (ans.size() > 1 && ans[0] == 0) {
    cout << -1 << '\n';
    return;
  }
  for (long long i = 0; i < n; i++) {
    if (ans[i] == -1) ans[i]++;
  }
  bool all = 0;
  for (long long i = 0; i < n; i++) {
    if (ans[i] > 0) {
      all = 1;
      break;
    }
  }
  if (all == 0) {
    ans[0]++;
  }
  for (auto x : ans) cout << x;
  cout << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t beg = clock();
  long long t = 1;
  while (t--) {
    solve();
  }
  cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}
