#include <bits/stdc++.h>
using namespace std;
struct ac {
  int s, c;
};
ac a[10];
int ans[4];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i].s >> a[i].c;
  }
  int flag = 0;
  for (int i = 1; i <= m; i++) {
    if (ans[a[i].s] == 0 && a[i].s <= n) {
      ans[a[i].s] = a[i].c;
    } else if (a[i].s <= n && ans[a[i].s] == a[i].c && ans[a[i].s] != 0) {
    } else {
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << -1 << '\n';
  else {
    for (int i = 1; i <= 3; i++) {
      if (ans[1] == 0) {
        cout << -1 << '\n';
        return 0;
      }
    }
    cout << ans[1] << ans[2] << ans[3] << '\n';
  }
}
