#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int ans[n];
  int s, c;
  for (int i = 0; i < n; i++) ans[i] = 0;
  for (int i = 0; i < (int)m; i++) {
    cin >> s >> c;
    if (ans[s - 1] == 0 || ans[s - 1] >= c) {
      ans[s - 1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (n == 1) {
    if (ans[0] == 0) {
      cout << 0 << endl;
      return 0;
    }
    cout << ans[0] << endl;
    return 0;
  } else if (n == 2) {
    if (ans[0] == 0 && ans[1] == 0) {
      cout << ans[2] << endl;
      return 0;
    }
    if (ans[0] == 0 && ans[1] != 0) {
      cout << ans[1] << ans[2] << endl;
      return 0;
    }
    if (ans[0] != 0) {
      cout << ans[0] << ans[1] << ans[2] << endl;
      return 0;
    }
  } else if (n == 3) {
    if (ans[0] == 0) {
      if (ans[1] == 0 && ans[2] == 0) {
        cout << -1 << endl;
        return 0;
      }
      if (ans[1] == 0 && ans[2] != 0) {
        cout << ans[2] << endl;
        return 0;
      }
      cout << ans[1] << ans[2] << endl;
      return 0;
    }
    cout << ans[0] << ans[1] << ans[2] << endl;
  }
  return 0;
}
