#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 5;
int c[10], cnt[10];
int main() {
  memset(c, 0, sizeof(c));
  int n, m;
  cin >> n >> m;
  int x, y;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    cnt[x]++;
    if (x < 1 || x > n || y < 0 || y > 9) {
      cout << -1 << endl;
      return 0;
    }
    if (cnt[x] > 1) {
      if (c[x] != y) {
        cout << -1;
        return 0;
      }
    }
    c[x] = y;
  }
  if (n > 3 || n < 1 || m < 0 || m > 5) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1) {
    if (c[1] > 0)
      cout << c[1] << endl;
    else
      cout << 0 << endl;
  }
  if (n > 1) {
    for (int i = 1; i <= n; i++) {
      if (i == 1) {
        if (c[i] > 1)
          cout << c[i];
        else if (c[i] == 0) {
          cout << -1;
          return 0;
        } else
          cout << 1;
      } else {
        if (c[i] > 0)
          cout << c[i];
        else
          cout << 0;
      }
    }
  }
  return 0;
}
