#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cout << fixed << setprecision(10);
  int n, m;
  int mini, maxi;
  map<int, int> sc;
  int ans = 0;
  bool flg = true;
  cin >> n >> m;
  switch (n) {
    case 1:
      mini = 0;
      maxi = 9;
      break;
    case 2:
      mini = 10;
      maxi = 99;
      break;
    case 3:
      mini = 100;
      maxi = 999;
      break;
    default:
      break;
  }
  for (long long i = (long long)(0); i < (long long)(m); ++i) {
    int ss, cc;
    cin >> ss >> cc;
    if (sc.count(ss)) {
      if (sc[ss] != cc) {
        flg = false;
      }
    } else {
      sc[ss] = cc;
    }
  }
  if (!flg) {
    cout << "-1"
         << "\n";
    ;
    return 0;
  } else {
    if (sc.count(1)) {
      ans += sc[1] * 100;
    }
    if (sc.count(2)) {
      ans += sc[2] * 10;
    }
    if (sc.count(3)) {
      ans += sc[3];
    }
    if (!sc.count(abs(n - 4))) {
      ans += mini;
    }
    if (mini <= ans && ans <= maxi) {
      cout << ans << "\n";
      ;
    } else {
      cout << "-1"
           << "\n";
      ;
    }
  }
  return 0;
}
