#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s[20], c[20], ans[5] = {-1, -1, -1, -1, -1};
  cin >> N >> M;
  for (int i = 1; i <= M; i++) cin >> s[i] >> c[i];
  int result = 0;
  if (N == 0) {
  } else {
    for (int i = 1; i <= M; i++) {
      if (ans[s[i]] == -1) {
        ans[s[i]] = c[i];
      } else if (ans[s[i]] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
    for (int j = 1; j <= N; j++) {
      if (ans[j] == -1) ans[j] = 0;
    }
    if (N == 1) {
      cout << ans[1] << endl;
    } else if (ans[1] == 0) {
      cout << -1 << endl;
      return 0;
    } else if (N == 2) {
      result = ans[2] + ans[1] * 10;
      cout << result << endl;
      return 0;
    } else {
      result = ans[3] + ans[2] * 10 + ans[1] * 100;
      cout << result << endl;
      return 0;
    }
    cout << result << endl;
    return 0;
  }
}
