#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
  int N;
  cin >> N;
  int check[4];
  memset(check, 0, sizeof check);
  int ans[4];
  memset(ans, 0, sizeof ans);
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (check[a] == 1 && b != ans[a]) {
      cout << -1 << endl;
      return 0;
    }
    if (check[a] == 0 || (check[a] == 1 && b == ans[a])) {
      ans[a] = b;
    }
  }
  if (ans[1] == 0 || N == 2 && ans[1] > 0 ||
      N == 1 && (ans[2] > 0 || ans[1] > 0))
    cout << -1 << endl;
  else
    cout << ans[1] * 100 + ans[2] * 10 + ans[3] << endl;
  return 0;
}
