#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string ans = "0000";
  for (int i = 0; i < m; i++) {
    int in, num;
    cin >> in >> num;
    if (in > n)
      return cout << "-1", 0;
    else if (ans[in] == '0')
      ans[in] = num + '0';
    else if (ans[in] != num + '0')
      return cout << "-1", 0;
  }
  if (ans[1] == '0') return cout << "-1", 0;
  for (int i = 1; i <= n; i++) cout << ans[i];
}
