#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
using V = vector<long long>;
void solve_abc() {
  long long n, m;
  long long ans = 0;
  cin >> n >> m;
  vector<P> q(m);
  long long s, c;
  for (long long i = 0; i < (long long)(m); i++) {
    cin >> s >> c;
    q[i] = make_pair(s, c);
  }
  V d(n, -1);
  for (long long i = 0; i < (long long)(m); i++) {
    s = q[i].first - 1;
    c = q[i].second;
    if (d[s] != -1) {
      if (d[s] != c) {
        cout << "-1"
             << "\n";
        return;
      }
    } else {
      d[s] = c;
    }
  }
  if (n == 1 && d[0] == 0) {
    cout << "0"
         << "\n";
    return;
  }
  if (d[0] <= 0) {
    cout << "-1"
         << "\n";
    return;
  }
  for (long long i = 0; i < (long long)(n); i++) {
    if (d[i] == -1) {
      cout << "0";
    } else {
      cout << d[i];
    }
  }
  cout << "\n";
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve_abc();
  return 0;
}
