#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();
int main() {
  pair<int, int> sc;
  ll N, M;
  cin >> N >> M;
  int s[M], c[M];
  int A[N];
  for (int i = 0; i < (N); i++) A[i] = 0;
  A[0] = 0;
  for (int i = 0; i < (M); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (M); i++) {
    for (int j = 0; j < (M); j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < (N); i++) {
    for (int j = 0; j < (M); j++) {
      if (i + 1 == s[j]) {
        A[i] = c[j];
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < (N); i++) {
    ans *= 10;
    ans += A[i];
  }
  if (ans < pow(10, N - 1) - 1)
    cout << "-1" << endl;
  else
    cout << ans << endl;
  return 0;
  return 0;
}
