#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 922337203685477;
const long long mininf = -922337203685477;
const long long nax = 0;
long long n, m, s[10], c[10];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
  }
  for (long long i = 1; i <= 9; i++) {
    for (long long j = 0; j <= 9; j++) {
      for (long long k = 0; k <= 9; k++) {
        bool bl = 1;
        for (long long g = 1; g <= m; g++) {
          if (s[g] == 1) {
            if (i != c[g]) {
              bl = 0;
              break;
            }
          } else if (s[g] == 2) {
            if (j != c[g]) {
              bl = 0;
              break;
            }
          } else {
            if (k != c[g]) {
              bl = 0;
              break;
            }
          }
        }
        if (bl) {
          if (n == 1) {
            cout << i << '\n';
          }
          if (n == 2) {
            cout << i << j << '\n';
          }
          if (n == 3) {
            cout << i << j << k << '\n';
          }
          return 0;
        }
      }
    }
  }
  cout << -1 << '\n';
}
