#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4 * atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
int N;
int M;
int s[20], c[20];
void solve() {
  if (N == 1) {
    if (M == 0) {
      cout << 0 << '\n';
      return;
    }
    if (M == 1 && s[0] == 1 && c[0] == 0) {
      cout << 0 << '\n';
      return;
    }
  }
  for (int i = 1; i <= 999; ++i) {
    string ss = to_string(i);
    bool ok = true;
    for (int j = 0; j < M; ++j) {
      if (ss[s[j] - 1] != c[j] + '0') {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << '\n';
      return;
    }
  }
  cout << -1 << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 0; i < M; ++i) cin >> s[i] >> c[i];
  solve();
  return 0;
}
