#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> dig(3, 10);
  for (int i = 0; i < m; i++) {
    if (dig[s[i] - 1] == 10) dig[s[i] - 1] = c[i];
    if (dig[s[i] - 1] != c[i]) {
      cout << "-1\n";
      return 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    if (dig[i] == 10) dig[i] = 0;
    ans += pow(10, 2 - i) * dig[i];
  }
  if (ans == 0 && n > 1) ans = -1;
  cout << ans << "\n";
}
