#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;
  cin >> n >> m;
  int minimum = 1;
  for (long long i = (long long)(0); i < (long long)(n - 1); ++i) {
    minimum *= 10;
  }
  map<int, int> sc;
  bool flg = true;
  for (long long i = (long long)(0); i < (long long)(m); ++i) {
    int a, b;
    cin >> a >> b;
    if (sc.count(a)) {
      if (sc[a] != b) {
        flg = false;
      }
    } else {
      sc[a] = b;
    }
  }
  int ans = -1;
  if (flg) {
    ans = 0;
    if (sc.count(1)) {
      ans += sc[1] * 100;
    }
    if (sc.count(2)) {
      ans += sc[2] * 10;
    }
    if (sc.count(3)) {
      ans += sc[3];
    }
    if (ans < minimum) ans = -1;
  }
  cout << ans << "\n";
  ;
  return 0;
}
