#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vc = vector<char>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
int dig(int a) {
  int ans = 1;
  for (int i = 0; i < a; i++) {
    ans *= 10;
  }
  return ans;
}
int main() {
  int n, m, s, c, ans = 0;
  bool flag = 0;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (mp.count(s) && mp.at(s) != c) {
      flag = 1;
    } else {
      mp[s] = c;
    }
  }
  if (n > 1 && mp[1] == 0) {
    flag = 1;
  }
  for (int i = 0; i < n; i++) {
    ans += mp[i + 1] * dig(n - i - 1);
  }
  if (flag) {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
