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