#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
const int inf(0x3fffffff);
const int mod(1000000007);
const double pi(acos(-1.0));
signed main() {
  {
    ios::sync_with_stdio(0);
    cin.tie(0);
  };
  int n, m;
  cin >> n >> m;
  int ret = 0;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0 && n != 1 ||
        s == n - 2 && ret / 100 && ret / 100 != c ||
        s == n - 1 && ret / 10 % 10 && ret / 10 % 10 != c ||
        s == n && ret % 10 && ret % 10 != c) {
      ret = -1;
      break;
    }
    if (s == n - 2 && ret / 100 != c)
      ret += c * 100;
    else if (s == n - 1 && ret / 10 % 10 != c)
      ret += c * 10;
    else if (ret % 10 != c)
      ret += c;
  }
  cout << ret;
  return 0;
}
