#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[n + 1];
  for (int i = 0; i <= n; i++) {
    s[i] = 1000;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (x == 1 && y == 0) continue;
    s[x] = min(s[x], y);
  }
  string ans;
  for (int i = 1; i <= n; i++) {
    if (s[1] == 1000) {
      cout << -1;
      return 0;
    }
    if (s[i] == 1000 && i > 1)
      ans.push_back('0');
    else
      ans.push_back(s[i] + '0');
  }
  cout << ans;
}
