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