#include <bits/stdc++.h>
using namespace std;
const long long INF = long long(1e18) + 1;
const double PI = 3.14159265358979323846;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int> > vp(M);
  for (int i = 0; i < M; i++) cin >> vp[i].first >> vp[i].second;
  sort(vp.begin(), vp.end());
  bool same = false;
  for (int i = 0; i < M; i++) {
    if (i != 0 && vp[i - 1].first == vp[i].first)
      same = true;
    else
      same = false;
    if ((vp[i].first == 1 && vp[i].second == 0) ||
        (same && vp[i - 1].second != vp[i].second)) {
      cout << -1 << endl;
      return 0;
    }
  }
  string ans = "";
  for (int i = 0; i < N; i++) {
    bool done;
    for (int j = 0; j < M; j++) {
      if (i == (vp[j].first - 1)) {
        ans += to_string(vp[j].second);
        done = true;
        break;
      } else
        done = false;
    }
    if (i == 0 && !done) {
      ans += "9";
    } else if (!done)
      ans += "0";
  }
  cout << ans << endl;
}
