#include <bits/stdc++.h>
using namespace std;
struct data {
  long long s, c;
};
bool cmp(const data& m, const data& n) { return m.s < n.s; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<data> d(m);
  for (int(i) = (0); (i) < (m); i++) cin >> d[i].s >> d[i].c;
  sort(d.begin(), d.end(), cmp);
  int ok = 0, ans = 0, dig[3] = {};
  if (d[0].s != 1)
    ok = 0;
  else {
    int now = 0;
    for (int(i) = (0); (i) < (n); i++) {
      if (now != d[i].s - 1) {
        now = d[i].s - 1;
        dig[now] = d[i].c;
        ok = 1;
      } else {
        if (dig[now] != 0 && dig[now] != d[i].c) {
          ok = 0;
          break;
        } else {
          dig[now] = d[i].c;
          ok = 1;
        }
      }
    }
    if (n == 3)
      ans = dig[0] * 100 + dig[1] * 10 + dig[2];
    else if (n == 2)
      ans = dig[0] * 10 + dig[1];
    else
      ans = dig[0];
  }
  int buf = 1;
  if (dig[0])
    buf = 3;
  else if (dig[1])
    buf = 2;
  if (ok && buf == n)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
