#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long maxi = INT_MIN;
  long long mini = INT_MAX;
  long long n, m;
  cin >> n >> m;
  vector<long long> v;
  for (long long i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    v.push_back(a);
    maxi = max(maxi, a);
    mini = min(mini, a);
  }
  long long arr[m][2];
  for (long long i = 0; i < m; ++i) {
    for (long long j = 0; j < 2; ++j) {
      cin >> arr[i][j];
    }
  }
  vector<long long> temp = v;
  vector<long long> final = v;
  vector<long long> finalans;
  long long ans = maxi - mini;
  for (long long i = 0; i < n; ++i) {
    long long mini1 = INT_MAX;
    long long maxi1 = INT_MIN;
    vector<long long> t;
    temp = v;
    maxi1 = v[i];
    for (long long j = 0; j < m; ++j) {
      if ((i + 1) < arr[j][0] || (i + 1) > arr[j][1]) {
        t.push_back(j + 1);
        for (long long k = arr[j][0] - 1; k < arr[j][1]; ++k) {
          temp[k]--;
          mini1 = min(mini1, temp[k]);
        }
      }
    }
    if (ans < maxi1 - mini1) {
      ans = maxi1 - mini1;
      final = temp;
      finalans = t;
    }
  }
  cout << ans << "\n";
  cout << finalans.size() << "\n";
  for (long long i = 0; i < finalans.size(); ++i) {
    cout << finalans[i] << " ";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
