#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using ll = long long;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
const int mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  set<P> st;
  bool ok = false;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c != 0) ok = true;
    st.insert(make_pair(s, c));
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  auto it = st.begin();
  for (int i = 0; i < st.size() - 1; i++) {
    int a = (*it).first;
    it++;
    int b = (*it).first;
    if (a == b) {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  for (P p : st) {
    ans += pow(10, n - p.first) * p.second;
  }
  cout << ans << endl;
}
