#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  int a[m], b[m];
  int p = 1;
  for (int i = 1; i < n; i++) {
    p = p * 10;
  }
  if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
    } else {
      cout << p << endl;
    }
    return 0;
  }
  vector<pair<int, int> > par;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    par.push_back(make_pair(a[i], b[i]));
  }
  sort(par.begin(), par.end());
  if (par[0].first == 1 && par[0].second == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (m - 1); i++) {
    if (par[i].first == par[i + 1].first) {
      if (par[i].second != par[i + 1].second) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int t = 0;
  int br = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (i == par[j].first) {
        t = 1;
        br = br + p * par[j].second;
        break;
      }
    }
    if (t == 0) {
      if (i == 1) {
        br = br + p * 1;
      } else {
        br = br + 0;
      }
    }
    p = p / 10;
    t = 0;
  }
  cout << br << endl;
}
