#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll res = 1000000007;
int main() {
  ll n, m, ans = 0, dgt1 = 10, dgt2 = 10, dgt3 = 10;
  cin >> n >> m;
  vector<ll> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < m; i++) {
    if (s[i] == 1 && c[i] == 0) ans = -1;
  }
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) ans = -1;
    }
  if (ans != -1) {
    for (int i = 0; i < m; i++) {
      if (s[i] == 1 && dgt1 > c[i])
        dgt1 = c[i];
      else if (s[i] == 2 && dgt2 > c[i])
        dgt2 = c[i];
      else if (s[i] == 3 && dgt3 > c[i])
        dgt3 = c[i];
    }
    if (dgt2 >= 10) dgt2 = 0;
    if (dgt3 >= 10) dgt3 = 0;
    if (n == 3)
      ans = 100 * dgt1 + 10 * dgt2 + dgt3;
    else if (n == 2)
      ans = 10 * dgt1 + dgt2;
    else if (n == 1)
      ans = dgt1;
  }
  cout << ans << endl;
}
