#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> s[6];
  for (int i = 1; i <= m; i++) cin >> s[i].first >> s[i].second;
  int ans[6] = {0};
  sort(s, s + m);
  for (int i = 1; i <= m; i++) {
    if (ans[s[i].first] == 0)
      ans[s[i].first] = s[i].second;
    else if (ans[s[i].first] != s[i].second) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (s[i].first == 1 && s[i].second == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (ans[i] == 0 && i == m)
      cout << 1;
    else
      cout << ans[i];
  }
  return 0;
}
