#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;
  if (!m) {
    cout << -1 << endl;
    return 0;
  }
  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] = {};
  int now = -1;
  for (int(i) = (0); (i) < (m); i++) {
    if (now == d[i].s - 1) {
      if (dig[now] == d[i].c)
        ok = 1;
      else {
        ok = 0;
        break;
      }
    } else {
      now = d[i].s - 1;
      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 = 0;
  if (dig[n - 1]) buf = 1;
  if (n > 1 && dig[n - 2]) buf = 2;
  if (n > 2 && dig[n - 3]) buf = 3;
  if (ok && buf == n)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
