#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < (M); ++i) {
    cin >> s[i] >> c[i];
  }
  ll ans = 0;
  int num[M + 1];
  for (int i = 0; i < (4); ++i) num[i] = -1;
  for (int i = 0; i < (M); ++i) {
    if (num[s[i]] == c[i] || num[s[i]] == -1) {
      num[s[i]] = c[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  ll ten = 1;
  if (N == 3 && num[1] == 0 || (N == 2 && (num[1] >= 1 || num[2] == 0)) ||
      (N == 1 && (num[1] >= 1 || num[2] >= 1))) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 3; i >= 1; --i) {
    if (num[i] != -1) ans += num[i] * ten;
    ten *= 10;
  }
  if (N == 3 && num[1] == -1) {
    ans += 100;
  } else if (N == 2 && num[2] == -1) {
    ans += 10;
  }
  cout << ans << endl;
}
