#include <bits/stdc++.h>
using namespace std;
int ans = -1;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> dm;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (dm.count(s)) {
      if (dm[s] != c) {
        cout << -1 << endl;
        return 0;
      } else {
        continue;
      }
    }
    dm.emplace(make_pair(s, c));
  }
  if (n == 1) {
    if (dm.count(1) > 0)
      ans = dm[1];
    else
      ans = 0;
    cout << ans << endl;
    return 0;
  }
  if (dm[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 2) {
    if (dm.count(2) > 0)
      ans = dm[2];
    else
      ans = 0;
    if (dm.count(1) > 0)
      ans += dm[1] * 10;
    else
      ans += 10;
  } else if (n == 3) {
    if (dm.count(3) > 0)
      ans = dm[3];
    else
      ans = 0;
    if (dm.count(2) > 0) ans += dm[2] * 10;
    if (dm.count(1) > 0)
      ans += dm[1] * 100;
    else
      ans += 100;
  }
  cout << ans << endl;
  return 0;
}
