#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e18 + 10;
const double PI = acos(-1);
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int dy[] = {-1, 1, 0, 0};
int dx[] = {0, 0, -1, 1};
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
    --s[i];
  }
  vector<int> digit(N, -1);
  for (int i = 0; i < M; ++i) {
    if (digit[s[i]] > -1 && digit[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    if (s[i] == 0 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    digit[s[i]] = c[i];
  }
  if (digit[0] == -1)
    cout << 1;
  else
    cout << digit[0];
  for (int i = 1; i < N; ++i) {
    if (digit[i] == -1)
      cout << 0;
    else
      cout << digit[i];
  }
  cout << endl;
  return 0;
}
