#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  cin >> n >> m;
  int s[m];
  int c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  int yy = 0;
  map<int, int> mp;
  for (int i = 0; i < m; i++) {
    if (mp.find(s[i]) != mp.end()) {
      yy = 1;
      break;
    } else
      mp[s[i]] = c[i];
  }
  if (yy == 1)
    cout << -1 << endl;
  else {
    int N = n;
    if (N > 1 && mp.find(1) != mp.end() && mp[1] == 0)
      cout << -1 << endl;
    else {
      if (N == 1) {
        if (mp.find(1) != mp.end())
          cout << mp[1] << endl;
        else
          cout << 0 << endl;
      } else if (N == 2) {
        int num = 0;
        if (mp.find(1) != mp.end())
          num = mp[1];
        else
          num = 1;
        if (mp.find(2) != mp.end())
          num = num * 10 + mp[2];
        else
          num = 10;
        cout << num << endl;
      } else {
        int num = 0;
        if (mp.find(1) != mp.end())
          num = mp[1];
        else
          num = 1;
        if (mp.find(2) != mp.end())
          num = num * 10 + mp[2];
        else
          num = 10;
        if (mp.find(3) != mp.end())
          num = num * 10 + mp[3];
        else
          num * 10;
        cout << num << endl;
      }
    }
  }
  return 0;
}
