#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int cnt[3][10];
  bool flag = true;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 10; ++j) {
      cnt[i][j] = 0;
    }
  }
  for (int i = 0, q1, q2; i < m; ++i) {
    cin >> q1 >> q2;
    q1 = n - q1;
    cnt[q1][q2]++;
  }
  int index[3];
  for (int i = 0; i < 3; ++i) index[i] = 0;
  for (int i = 0; i < n; ++i) {
    flag = true;
    for (int j = 0; j < 10; ++j) {
      if (cnt[i][j] > 0) {
        if (!flag) {
          cout << "-1" << endl;
          return 0;
        } else {
          flag = false;
          index[i] = j;
        }
      }
    }
  }
  if (n > 1 && index[n - 1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0, base = 1; i < n; ++i, base *= 10) {
    ans += index[i] * base;
  }
  cout << ans << endl;
}
