#include <bits/stdc++.h>
using namespace std;
int a[10];
int s[10];
int c[10];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int mn = 1000000000;
  bool flag = 0;
  if (n == 1) {
    for (int i = 1; i < 10; i++) {
      a[0] = i;
      for (int l = 0; l < m; l++) {
        if (a[s[l] - 1] != c[l]) break;
        if (l == m - 1) {
          flag = 1;
          mn = min(mn, i);
        }
      }
    }
  } else if (n == 2) {
    for (int i = 1; i < 10; i++) {
      a[0] = i;
      for (int j = 0; j < 10; j++) {
        a[1] = j;
        for (int l = 0; l < m; l++) {
          if (a[s[l] - 1] != c[l]) break;
          if (l == m - 1) {
            flag = 1;
            mn = min(mn, i * 10 + j);
          }
        }
      }
    }
  } else if (n == 3) {
    for (int i = 1; i < 10; i++) {
      a[0] = i;
      for (int j = 0; j < 10; j++) {
        a[1] = j;
        for (int k = 0; k < 10; k++) {
          a[2] = k;
          for (int l = 0; l < m; l++) {
            if (a[s[l] - 1] != c[l]) break;
            if (l == m - 1) {
              flag = 1;
              mn = min(mn, i * 100 + j * 10 + k);
            }
          }
        }
      }
    }
  }
  if (!flag)
    cout << -1 << endl;
  else
    cout << mn << endl;
  return 0;
}
