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