#include <bits/stdc++.h>
using namespace std;
int n, m, i, x, y, a[6], b[6];
bool t;
int main() {
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    a[i] = x * 100 + y;
    if (x > n) t = true;
    if (x == 1 && y == 0) t = true;
  }
  if (t == true) {
    cout << -1;
    return 0;
  }
  sort(a + 1, a + m + 1);
  for (i = 1; i <= m; i++)
    if (a[i] / 100 == a[i + 1] / 100 && a[i] % 10 != a[i + 1] % 10) {
      t = true;
      break;
    } else {
      x = a[i] / 100;
      b[x] = a[i] % 10;
    }
  if (t == true)
    cout << -1 << endl;
  else
    for (i = 1; i <= n; i++)
      if (i == 1 && b[i] == 0)
        cout << 1;
      else
        cout << b[i];
}
