#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  bool exist = true;
  int N, M, s, c;
  cin >> N >> M;
  vector<int> v(N + 1);
  vector<bool> check(N + 1, false);
  for (int i = 0; i < (int)M; i++) {
    cin >> s >> c;
    if (s == 1 && c == 0) exist = false;
    if (check[s] == true && v[s] != c) exist = false;
    check[s] = true;
    v[s] = c;
  }
  if (!exist) {
    cout << -1 << endl;
    return 0;
  }
  if (check[1] == false) v[1] = 1;
  int ret = 0;
  for (int i = 0; i < (int)N + 1; i++) {
    if (check[i]) ret += (pow(10, N - i) * v[i]);
  }
  cout << ret << endl;
  return 0;
}
