#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, 9);
  vector<bool> marked(n, false);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    num[s] = min(num[s], c);
    marked[s] = true;
  }
  string str;
  for (int i = 0; i < m; i++) str += marked[i] ? num[i] + '0' : '0';
  int i = 0;
  while (str[i] == '0') i++;
  cout << (i ^ 0 ? "-1" : str) << endl;
}
int main() {
  solve();
  return 0;
}
