#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n = 0, k = 0, flag = 0;
  cin >> n >> k;
  map<int, int> m;
  for (int i = 0; i < k; i++) {
    int si, ci;
    cin >> si >> ci;
    si--;
    if (si == 0 && ci == 0 && n > 1) {
      flag = 1;
    }
    if (m.find(si) != m.end()) {
      if (m[si] != ci) {
        flag = 1;
      }
    } else
      m[si] = ci;
  }
  if (flag == 1) {
    cout << -1 << "\n";
    return;
  }
  vector<int> res(n);
  for (auto x : m) {
    res[x.first] = x.second;
  }
  int ans = 0, c = 1;
  for (int i = n - 1; i >= 0; i--) {
    ans += (c * res[i]);
    c *= 10;
  }
  cout << ans << "\n";
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
