#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int num[10];
  for (int i = 1; i < 10; i++) num[i] = -1;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    if (num[a] == -1)
      num[a] = b;
    else if (num[a] != -1)
      num[a] = min(num[a], b);
  }
  int flag = 1;
  if (num[1] == -1 || num[1] == 0) flag = 0;
  if (flag == 0)
    cout << "-1" << endl;
  else {
    for (int i = 1; i <= m; i++)
      if (num[i] == -1) num[i] = 0;
    for (int i = 1; i <= m; i++) cout << num[i];
  }
}
