#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  vector<int> a(n + 1, 10);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (a[s] > c) {
      a[s] = c;
    }
  }
  if (n == 1) {
    if (a[1] == 10) ans = 0;
  } else {
    for (int i = 1; i < 4; i++) {
      if ((a[1] == 0)) {
        ans = -1;
        break;
      }
      if (a[i] == 10 && i == 1)
        a[i] = 1;
      else if (a[i] == 10)
        a[i] = 0;
      ans += a[i] * pow(10, n - i);
    }
  }
  cout << ans;
}
