#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    arr[i] = -1;
  }
  for (int i = 0; i < m; ++i) {
    int t1, t2;
    cin >> t1 >> t2;
    if (arr[t1 - 1] == -1 || arr[t1 - 1] == t2)
      arr[t1 - 1] = t2;
    else {
      cout << "-1\n";
      return 0;
    }
  }
  if (arr[0] == -1 || arr[0] == 0) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (arr[i] == -1) arr[i] = 0;
    cout << arr[i];
  }
  cout << "\n";
}
